Submission #1870889
Source Code Expand
#include <bits/stdc++.h> #define rank tipa_rank #define pb push_back #define mp make_pair #define ll long long #define ull unsigned long long #define INF 1000000000 #define EPS 1e-6 #define free tipa_free #define EPS2 1e-8 using namespace std; const ll MOD = INF + 7; using namespace std; string s; string ans; int n , k; deque<pair<char , int> > v; bool swapped = false; int main() { //freopen("output.txt" , "w" , stdout); cin >> n >> k; cin >> s; for(int i = 0; i < s.size(); i++) { if(v.size() && v.back().first == s[i]) v.back().second++; else v.push_back(mp(s[i] , 1)); } if(n == 1) { cout << char(((s[0] - 'A') ^ (k % 2)) + 'A'); return 0; } /*for(int i = 0; i < v.size(); i++) cout << v[i].first << " " << v[i].second << endl; cout << endl;*/ int cnt = 0; while(k--) { if(v.front().first == 'A' + swapped) { v.front().second--; if(!v.front().second) v.pop_front(); if(v.front().first == 'B' - swapped) { v.front().second++; } else v.push_front(mp('B' - swapped , 1)); } else { //v.pop_front(); v.front().second--; if(!v.front().second) v.pop_front(); swapped = !swapped; if(v.back().first == swapped + 'A') v.back().second++; else v.push_back(mp(swapped + 'A' , 1)); } /*cout << swapped << endl; for(int i = 0; i < v.size(); i++) cout << v[i].first << " " << v[i].second << endl; cout << endl;*/ cnt++; if(cnt == 500000) { break; } } if((k + 1) % 2 && n % 2) { v.pop_front(); v.front().second++; } //cout << v[0].first - 'A' << endl; for(int i = 0; i < v.size(); i++) { if(!swapped) { for(int j = 0; j < v[i].second; j++) cout << v[i].first; } else { for(int j = 0; j < v[i].second; j++) cout << char(((v[i].first - 'A') ^ 1) + 'A'); } } }
Submission Info
Submission Time | |
---|---|
Task | A - Airport Bus |
User | Danylo1999 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1907 Byte |
Status | WA |
Exec Time | 2 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt |
All | sample1.txt, sample2.txt, in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, sample1.txt, sample2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | WA | 1 ms | 256 KB |
in2.txt | WA | 1 ms | 256 KB |
in3.txt | WA | 1 ms | 256 KB |
in4.txt | WA | 1 ms | 256 KB |
in5.txt | WA | 1 ms | 256 KB |
in6.txt | WA | 2 ms | 256 KB |
in7.txt | WA | 1 ms | 256 KB |
in8.txt | WA | 1 ms | 256 KB |
sample1.txt | WA | 1 ms | 256 KB |
sample2.txt | WA | 1 ms | 256 KB |