For the time being, to the point where it was solved. .. .. Problems that cannot be solved during the contest cannot be solved by looking at the editorial. .. ..
--Output the first character
private void solveA() {
String s = next();
out.println(s.charAt(0));
}
--The result of performing the operation "move the first character to the end" $ K times.
――This kind of problem, if you rotate it properly, you will definitely not have enough time
――As if you rotated it, add letters to the back
--Cut out the length of the original character from the kth of the generated character string
Input example 2: JKrolling 99
Character string after generation (cut out from 99th to 108th here and output)
JKrollingJKrollingJKrollingJKrollingJKrollingJKrollingJKrollingJKrollingJKrollingJKrollingJKrollingJKrolling
private void solveB() {
String s = next();
int k = nextInt();
List<String> wk = new ArrayList<String>();
for (int i = 0; i < s.length(); i++) {
wk.add(s.substring(i, i + 1));
}
for (int i = 0; i < k; i++) {
wk.add(wk.get(i));
// wk.remove(0);
}
StringBuilder builder = new StringBuilder();
for (int i = k; i < wk.size(); i++) {
builder.append(wk.get(i));
}
out.println(builder.toString());
}
――Note that it is from 7 days ago to the day
private void solveC() {
int numN = nextInt();
int start = numN - 7;
for (int i = start; i <= numN; i++) {
out.println(i);
}
}
――Because it is the best way
--Sort the input values
--From behind, take in the order of Takahashi-> Aoki
private void solveD() {
int n = nextInt();
int x = nextInt();
int y = nextInt();
int[] wk = IntStream.range(0, n).map(i -> nextInt()).toArray();
Arrays.sort(wk);
int tak = 0;
int aok = 0;
for (int i = 0; i < wk.length; i++) {
if ((i & 1) == 1) {
aok += wk[wk.length - 1 - i];
} else {
tak += wk[wk.length - 1 - i];
}
}
tak += x;
aok += y;
if (aok > tak) {
out.println("Aoki");
} else if (aok < tak) {
out.println("Takahashi");
} else {
out.println("Draw");
}
}
--Rewritten version because it became TLE
--If you don't go on a date for a day, you can find out the devotion date by $ devotion date-dedication date / vacation $ --Anniversary is 0th, 1st is branched --Anniversary The last day of the loop of 2 days or more branches --In addition to normal processing, processing from the last anniversary to the last day is added
private void solveE() {
long n = nextLong();
long a = nextLong();
long b = nextLong();
List<Long> day = new ArrayList<Long>();
for (int i = 0; i < b; i++) {
day.add(nextLong());
}
long res = 0;
/*
*There is no anniversary
*/
if (day.size() == 0) {
long d = n - 1;
long val = d - d / a;
res += val;
out.println(res);
return;
}
/*
*Anniversary for only one day
*/
if (day.size() == 1) {
long d = 0;
long val = 0;
d = day.get(0) - 1;
val = d - d / a;
res += val;
d = n - day.get(0);
val = d - d / a;
res += val;
out.println(res);
return;
}
Collections.sort(day);
long d = 0;
for (int wkCnt = 0; wkCnt <= n; wkCnt++) {
if (wkCnt == day.size() - 1) {
/*
*At the last time
*・ Holiday processing
*・ Processing from the last day (n) to the last holiday
*Implemented two
*/
d = day.get(wkCnt) - day.get(wkCnt - 1) - 1;
long val = d - d / a;
res += val;
d = n - day.get(wkCnt);
val = d - d / a;
res += val;
break;
} else if (wkCnt == 0) {
/*
*Initially
*/
d = (day.get(wkCnt) - 1);
} else if (wkCnt < day.size() - 1) {
/*
*To get only in the middle of the holiday
*Next holiday-After this holiday, additional-1
*/
d = day.get(wkCnt) - day.get(wkCnt - 1) - 1;
}
/*
* d/a is a holiday
*/
long val = d - d / a;
res += val;
}
out.println(res);
}
I implemented it honestly, but well TLE
--Set the date date in the set --Perform the following judgments every day --Whether it's an anniversary --If it is an anniversary, reset the count of consecutive days --Whether it's a date --Reset the count of consecutive days for date days ――Whether you have devoted yourself --If you devote yourself to res ++
/**
* TLE
*/
private void solveE2() {
long n = nextLong();
long a = nextLong();
long b = nextLong();
Set<Long> day = new HashSet<Long>();
for (int i = 0; i < b; i++) {
day.add(nextLong());
}
// StringBuilder builder = new StringBuilder();
long dayCnt = 0;
long res = 0;
// List<Long> add = new ArrayList<Long>();
long cnt = 1;
while (cnt <= n) {
dayCnt++;
if (dayCnt == a) {
dayCnt = 0;
// builder.append("D");
} else if (day.contains(cnt)) {
dayCnt = 0;
// builder.append("D");
} else {
res++;
// add.add(i);
// builder.append("P");
}
cnt++;
}
out.println(res);
}
--Prime factorization --If it is the same as k, sort and output as it is --If less than k, -1 --If it is larger than k, multiply all the values after the kth and combine them into one.
private void solveF() {
long n = nextLong();
long k = nextLong();
List<Integer> wk = new ArrayList<Integer>();
for (int i = 2; i <= n; i++) {
while (n % i == 0) {
wk.add(i);
n /= i;
}
}
StringBuilder builder = new StringBuilder();
if (wk.size() == k) {
for (Integer integer : wk) {
builder.append(integer + " ");
}
} else if (wk.size() < k) {
builder.append(-1);
} else {
int cnt = 1;
for (int i = 0; i < wk.size(); i++) {
if (i < k - 1) {
builder.append(wk.get(i) + " ");
} else {
cnt *= wk.get(i);
}
}
builder.append(cnt);
}
out.println(builder.toString());
}