Submission #1627714
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){ assert(a&&b); 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(i<n&&s[i]=='B'){ if(i!=n-1&&s[i+1]=='A'); else s[i]='A'; i++; } if(i==n){ k--; continue; } while(i<n&&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(i<n&&s[i]=='B'){ i++; x++; } while(i<n&&s[i]=='A'){ i++; y++; }//cout<<x<<y<<endl; if(x==0||y==0){cout<<-1<<endl; return 0;} 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 | 2039 Byte |
Status | RE |
Exec Time | 125 ms |
Memory | 1540 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 | 1 ms | 256 KB |
in10.txt | RE | 122 ms | 1540 KB |
in11.txt | RE | 106 ms | 640 KB |
in12.txt | RE | 104 ms | 644 KB |
in13.txt | RE | 106 ms | 772 KB |
in14.txt | RE | 110 ms | 640 KB |
in15.txt | RE | 105 ms | 640 KB |
in16.txt | AC | 26 ms | 904 KB |
in17.txt | RE | 106 ms | 640 KB |
in18.txt | WA | 10 ms | 640 KB |
in19.txt | RE | 125 ms | 776 KB |
in2.txt | RE | 101 ms | 512 KB |
in20.txt | RE | 107 ms | 640 KB |
in21.txt | WA | 9 ms | 640 KB |
in22.txt | WA | 11 ms | 640 KB |
in23.txt | RE | 110 ms | 640 KB |
in24.txt | WA | 9 ms | 644 KB |
in25.txt | WA | 11 ms | 640 KB |
in26.txt | WA | 11 ms | 640 KB |
in27.txt | WA | 11 ms | 640 KB |
in28.txt | WA | 9 ms | 640 KB |
in29.txt | WA | 11 ms | 640 KB |
in3.txt | WA | 11 ms | 640 KB |
in30.txt | RE | 105 ms | 640 KB |
in31.txt | WA | 11 ms | 640 KB |
in32.txt | RE | 108 ms | 640 KB |
in33.txt | RE | 108 ms | 640 KB |
in34.txt | RE | 107 ms | 640 KB |
in35.txt | RE | 105 ms | 640 KB |
in36.txt | WA | 9 ms | 640 KB |
in37.txt | WA | 11 ms | 640 KB |
in38.txt | WA | 9 ms | 640 KB |
in39.txt | RE | 105 ms | 640 KB |
in4.txt | RE | 107 ms | 640 KB |
in40.txt | WA | 9 ms | 640 KB |
in41.txt | WA | 11 ms | 640 KB |
in42.txt | WA | 9 ms | 640 KB |
in5.txt | RE | 106 ms | 640 KB |
in543.txt | WA | 9 ms | 640 KB |
in557.txt | RE | 107 ms | 640 KB |
in6.txt | WA | 1 ms | 256 KB |
in7.txt | RE | 106 ms | 640 KB |
in8.txt | WA | 9 ms | 640 KB |
in9.txt | WA | 11 ms | 640 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |