Submission #1627681
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) int n,k; string s; string A(int x){ string s="";rep(i,x)s.pb('A');return s;} string B(int x){ string s="";rep(i,x)s.pb('B');return s;} string rec(int a,int b,int zan){ if(a>1&&b>1){ if(zan==0) return B(a)+A(b); if(zan==1) return A(a-1)+B(b)+A(1); if(zan==2) return B(1)+A(a-2)+B(b)+A(1); return rec(a-1,b-1,zan-3)+"BA"; } if(a==1&&b==1) return B(1)+A(1); if(zan==0) return B(a)+A(b); if(a==1){ if(zan==1) return B(a+b-1)+A(1); if(zan==2) return A(a+b-2)+B(1)+A(1); return rec(1,a+b-3,zan-3)+B(1)+A(1); } else{ if(zan==1) A(a+b-2)+B(1)+A(1); return rec(1,a+b-3,zan-2)+B(1)+A(1); } } int main(){ cin>>n>>k>>s; while(1){ if(k==0){ cout<<s<<endl; return 0; } if(s[0]=='A'){ s[0]='B'; k--; continue; }//cout<<"N"<<endl; for(int i=0;i<n;){ while(s[i]=='B'){ if(i!=n-1&&s[i+1]=='A'); else s[i]='A'; i++; } if(i==n){ k--; continue; } while(s[i]=='A'){ if(i!=n-1&&s[i+1]=='A') s[i]='B'; i++; } if(i==n){//cout<<s<<endl; k--; goto out; } } }out:; if(k==0){ cout<<s<<endl; return 0; } string ans = ""; for(int i=0;i<n;){ int x = 0,y = 0; while(s[i]=='B'){ i++; x++; } while(s[i]=='A'){ i++; y++; }//cout<<x<<y<<endl; ans+=rec(x,y,k); } cout<<ans<<endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Half Reflector |
User | IH19980412 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1955 Byte |
Status | RE |
Exec Time | 2108 ms |
Memory | 393604 KB |
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | WA | 2 ms | 256 KB |
in10.txt | WA | 415 ms | 31732 KB |
in11.txt | TLE | 2106 ms | 54608 KB |
in12.txt | TLE | 2106 ms | 55344 KB |
in13.txt | WA | 813 ms | 43300 KB |
in14.txt | TLE | 2106 ms | 53968 KB |
in15.txt | TLE | 2106 ms | 54472 KB |
in16.txt | AC | 27 ms | 904 KB |
in17.txt | TLE | 2105 ms | 53636 KB |
in18.txt | TLE | 2107 ms | 71116 KB |
in19.txt | WA | 52 ms | 19336 KB |
in2.txt | TLE | 2104 ms | 42680 KB |
in20.txt | TLE | 2105 ms | 54788 KB |
in21.txt | TLE | 2106 ms | 68028 KB |
in22.txt | RE | 465 ms | 393604 KB |
in23.txt | RE | 459 ms | 393604 KB |
in24.txt | RE | 456 ms | 393604 KB |
in25.txt | RE | 458 ms | 393604 KB |
in26.txt | RE | 458 ms | 393604 KB |
in27.txt | RE | 461 ms | 393604 KB |
in28.txt | TLE | 2105 ms | 46436 KB |
in29.txt | TLE | 2105 ms | 54148 KB |
in3.txt | TLE | 2106 ms | 53560 KB |
in30.txt | TLE | 2106 ms | 38704 KB |
in31.txt | TLE | 2106 ms | 43488 KB |
in32.txt | TLE | 2106 ms | 48940 KB |
in33.txt | TLE | 2105 ms | 54020 KB |
in34.txt | TLE | 2106 ms | 64124 KB |
in35.txt | TLE | 2107 ms | 50348 KB |
in36.txt | TLE | 2107 ms | 58996 KB |
in37.txt | TLE | 2108 ms | 64964 KB |
in38.txt | TLE | 2108 ms | 72368 KB |
in39.txt | TLE | 2105 ms | 37936 KB |
in4.txt | RE | 462 ms | 393604 KB |
in40.txt | TLE | 2105 ms | 38320 KB |
in41.txt | TLE | 2106 ms | 37172 KB |
in42.txt | TLE | 2106 ms | 38960 KB |
in5.txt | RE | 458 ms | 393604 KB |
in543.txt | WA | 1945 ms | 32768 KB |
in557.txt | WA | 1428 ms | 32768 KB |
in6.txt | RE | 451 ms | 393472 KB |
in7.txt | TLE | 2106 ms | 53124 KB |
in8.txt | RE | 460 ms | 393604 KB |
in9.txt | TLE | 2106 ms | 46924 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |