Submission #1158316
Source Code Expand
#ifdef DEBUG #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; typedef long double ld; #ifdef DEBUG #define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #else #define eprintf(...) ; #endif #define sz(x) ((int) (x).size()) #define TASK "text" const int inf = (int) 1.01e9; const ld eps = 1e-9; const ld pi = acos((ld) -1); mt19937 mrand(random_device{} ()); int rnd(int x) { return mrand() % x; } void precalc() { } const int maxn = (int) 2e5 + 5; int n, k; char tmp[maxn]; int a[maxn]; int read() { if (scanf("%d%d", &n, &k) < 2) { return false; } scanf("%s", tmp); for (int i = 0; i < n; i++) { a[i] = tmp[i] - 'A'; } return true; } void solve() { int pos = 0; int toxor = 0; while (k && pos != n) { if (a[pos] ^ toxor) { pos++; toxor ^= 1; } else { a[pos] ^= 1; } k--; } if (!k) { for (int i = 0; i < n; i++) { tmp[i] = 'A' + (a[i] ^ toxor); } rotate(tmp, tmp + pos, tmp + n); printf("%s\n", tmp); return; } pos = 0; if (!(n & 1)) { if (!(a[pos] ^ toxor)) { while (k && pos != n) { if (a[pos] ^ toxor) { pos++; toxor ^= 1; } else { a[pos] ^= 1; } k--; } if (!k) { for (int i = 0; i < n; i++) { tmp[i] = 'A' + (a[i] ^ toxor); } rotate(tmp, tmp + pos, tmp + n); printf("%s\n", tmp); return; } pos = 0; } assert(a[pos] ^ toxor); } else { if (a[pos] ^ toxor) { while (k && pos != n) { if (a[pos] ^ toxor) { pos++; toxor ^= 1; } else { a[pos] ^= 1; } k--; } if (!k) { for (int i = 0; i < n; i++) { tmp[i] = 'A' + (a[i] ^ toxor); } rotate(tmp, tmp + pos, tmp + n); printf("%s\n", tmp); return; } pos = 0; } assert(!(a[pos] ^ toxor)); } if (n & 1) { k %= 2; } else { k %= 1; } while (k) { if (a[pos] ^ toxor) { pos++; if (pos == n) { pos = 0; } toxor ^= 1; } else { a[pos] ^= 1; } k--; } for (int i = 0; i < n; i++) { tmp[i] = 'A' + (a[i] ^ toxor); } rotate(tmp, tmp + pos, tmp + n); printf("%s\n", tmp); } int main() { precalc(); #ifdef DEBUG assert(freopen(TASK ".in", "r", stdin)); assert(freopen(TASK ".out", "w", stdout)); #endif while (read()) { solve(); #ifdef DEBUG eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC); #endif } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Half Reflector |
User | aid |
Language | C++14 (GCC 5.4.1) |
Score | 900 |
Code Size | 2768 Byte |
Status | AC |
Exec Time | 4 ms |
Memory | 1408 KB |
Compile Error
./Main.cpp: In function ‘int read()’: ./Main.cpp:42:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s", tmp); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 900 / 900 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in5.txt, in543.txt, in557.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 1 ms | 256 KB |
in10.txt | AC | 3 ms | 1408 KB |
in11.txt | AC | 4 ms | 1408 KB |
in12.txt | AC | 3 ms | 1408 KB |
in13.txt | AC | 3 ms | 1408 KB |
in14.txt | AC | 4 ms | 1408 KB |
in15.txt | AC | 3 ms | 1408 KB |
in16.txt | AC | 3 ms | 1408 KB |
in17.txt | AC | 3 ms | 1408 KB |
in18.txt | AC | 3 ms | 1408 KB |
in19.txt | AC | 3 ms | 1408 KB |
in2.txt | AC | 2 ms | 896 KB |
in20.txt | AC | 3 ms | 1408 KB |
in21.txt | AC | 3 ms | 1408 KB |
in22.txt | AC | 4 ms | 1408 KB |
in23.txt | AC | 4 ms | 1408 KB |
in24.txt | AC | 4 ms | 1408 KB |
in25.txt | AC | 4 ms | 1408 KB |
in26.txt | AC | 4 ms | 1408 KB |
in27.txt | AC | 4 ms | 1408 KB |
in28.txt | AC | 3 ms | 1408 KB |
in29.txt | AC | 3 ms | 1408 KB |
in3.txt | AC | 3 ms | 1408 KB |
in30.txt | AC | 3 ms | 1408 KB |
in31.txt | AC | 3 ms | 1408 KB |
in32.txt | AC | 3 ms | 1408 KB |
in33.txt | AC | 3 ms | 1408 KB |
in34.txt | AC | 4 ms | 1408 KB |
in35.txt | AC | 4 ms | 1408 KB |
in36.txt | AC | 4 ms | 1408 KB |
in37.txt | AC | 4 ms | 1408 KB |
in38.txt | AC | 4 ms | 1408 KB |
in39.txt | AC | 3 ms | 1408 KB |
in4.txt | AC | 4 ms | 1408 KB |
in40.txt | AC | 3 ms | 1408 KB |
in41.txt | AC | 3 ms | 1408 KB |
in42.txt | AC | 3 ms | 1408 KB |
in5.txt | AC | 4 ms | 1408 KB |
in543.txt | AC | 3 ms | 1408 KB |
in557.txt | AC | 3 ms | 1408 KB |
in6.txt | AC | 1 ms | 256 KB |
in7.txt | AC | 3 ms | 1408 KB |
in8.txt | AC | 4 ms | 1408 KB |
in9.txt | AC | 3 ms | 1408 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |