Submission #1676109
Source Code Expand
#include <stdio.h> #include <iostream> #include <algorithm> #include <memory.h> using namespace std; typedef long long LL; const int maxn = 400005; int n,K;char str[maxn]; bool check(int pos,int rv) { char now=n&1?'A':'B'; if (rv) now='A'+'B'-now; for (int i=pos;i<=n;i++,now='A'+'B'-now) if (str[i]!=now) return false; for (int i=1;i<pos;i++,now='A'+'B'-now) if (str[i]!=now) return false; return true; } int main() { #ifdef Amberframe freopen("agc011d.in","r",stdin); freopen("agc011d.out","w",stdout); #endif scanf("%d %d %s",&n,&K,str+1);int pos=1,rv=0; for (int i=1;i<=n*2&&K;i++,K--) { if (str[pos]=='A') { if (rv) pos=pos%n+1,rv^=1; else str[pos]='B'; } else { if (rv) str[pos]='A'; else pos=pos%n+1,rv^=1; } } while (K&&!check(pos,rv)) { if (str[pos]=='A') { if (rv) pos=pos%n+1,rv^=1; else str[pos]='B'; } else { if (rv) str[pos]='A'; else pos=pos%n+1,rv^=1; } K--; } if (!K) { if (rv) for (int i=1;i<=n;i++) str[i]='A'+'B'-str[i]; for (int i=pos;i<=n;i++) printf("%c",str[i]); for (int i=1;i<pos;i++) printf("%c",str[i]); } else { if (n&1) printf("%c",K&1?'B':'A'); for (int i=1;i<=n/2;i++) printf("BA"); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Half Reflector |
User | Amberframe |
Language | C++14 (GCC 5.4.1) |
Score | 900 |
Code Size | 1267 Byte |
Status | AC |
Exec Time | 8 ms |
Memory | 640 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:27:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d %s",&n,&K,str+1);int pos=1,rv=0; ^
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 | 5 ms | 640 KB |
in11.txt | AC | 6 ms | 640 KB |
in12.txt | AC | 5 ms | 640 KB |
in13.txt | AC | 5 ms | 640 KB |
in14.txt | AC | 6 ms | 640 KB |
in15.txt | AC | 5 ms | 640 KB |
in16.txt | AC | 5 ms | 640 KB |
in17.txt | AC | 5 ms | 640 KB |
in18.txt | AC | 5 ms | 640 KB |
in19.txt | AC | 5 ms | 640 KB |
in2.txt | AC | 2 ms | 384 KB |
in20.txt | AC | 5 ms | 640 KB |
in21.txt | AC | 5 ms | 640 KB |
in22.txt | AC | 8 ms | 640 KB |
in23.txt | AC | 8 ms | 640 KB |
in24.txt | AC | 8 ms | 640 KB |
in25.txt | AC | 8 ms | 640 KB |
in26.txt | AC | 8 ms | 640 KB |
in27.txt | AC | 8 ms | 640 KB |
in28.txt | AC | 4 ms | 640 KB |
in29.txt | AC | 4 ms | 640 KB |
in3.txt | AC | 5 ms | 640 KB |
in30.txt | AC | 4 ms | 640 KB |
in31.txt | AC | 5 ms | 640 KB |
in32.txt | AC | 5 ms | 640 KB |
in33.txt | AC | 5 ms | 640 KB |
in34.txt | AC | 5 ms | 640 KB |
in35.txt | AC | 6 ms | 640 KB |
in36.txt | AC | 6 ms | 640 KB |
in37.txt | AC | 6 ms | 640 KB |
in38.txt | AC | 8 ms | 640 KB |
in39.txt | AC | 4 ms | 640 KB |
in4.txt | AC | 8 ms | 640 KB |
in40.txt | AC | 4 ms | 640 KB |
in41.txt | AC | 4 ms | 640 KB |
in42.txt | AC | 4 ms | 640 KB |
in5.txt | AC | 8 ms | 640 KB |
in543.txt | AC | 3 ms | 640 KB |
in557.txt | AC | 3 ms | 640 KB |
in6.txt | AC | 1 ms | 256 KB |
in7.txt | AC | 5 ms | 640 KB |
in8.txt | AC | 8 ms | 640 KB |
in9.txt | AC | 5 ms | 640 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |