Task: | Babaza Game |
Sender: | auni |
Submission time: | 2024-09-04 14:10:05 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
Code
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i,a,b) for (int i = a; i < b; i++) void solve(string &a, string &b, string &helper, vector<pii> intervals, char c) { vector<bool> didE(intervals.size(), false); vector<bool> didO(intervals.size(), false); REP(i, 0, (int)intervals.size()) { bool canOdd = true; bool canEven = true; pii inter = intervals[i]; int l = inter.F; int r = inter.S; for(int j = l; j <= r; j+=2) { if(b[j] == helper[j] || b[j] == helper[j+2]) { canOdd = false; } } for(int j = l+1; j <= r; j+=2) { if(b[j] == helper[j] || b[j] == helper[j+2]) { canEven = false; } } if(canEven) { didE[i] = true; for(int j = l+1; j <= r; j+=2) { a[j] = b[j]; } } else if(canOdd) { didO[i] = true; for(int j = l; j <= r; j+=2) { a[j] = b[j]; } } else { for(int j = l+1; j <= r; j+=2) { a[j] = c; } } } cout << a << "\n"; REP(i, 0, (int)intervals.size()) { pii inter = intervals[i]; int l = inter.F; int r = inter.S; if(didE[i]) { for(int j = l; j <= r; j+=2) { a[j] = b[j]; } } else if(didO[i]) { for(int j = l+1; j <= r; j+=2) { a[j] = b[j]; } } else { for(int j = l; j <= r; j+=2) { a[j] = b[j]; } } } cout << a << "\n"; bool all = true; REP(i, 0, (int)intervals.size()) { pii inter = intervals[i]; int l = inter.F; int r = inter.S; if(!didO[i] && !didE[i]) { for(int j = l+1; j <= r; j+=2) { a[j] = b[j]; } all = false; } } if(!all) cout << a << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); string a, b; cin >> a >> b; int n = a.length(); vector<int> ind; vector<pii> intervals; cout << a << "\n"; string helper = 'a' + a + 'a'; bool can1 = true; REP(i, 0, n) { if(a[i] != b[i]) ind.PB(i); } REP(i, 0, (int)ind.size()-1) { if(ind[i] - ind[i+1] == -1) { int l = ind[i]; int r = ind[i]; can1 = false; while(i+1 < n && ind[i] - ind[i+1] == -1) { r++; i++; } intervals.PB(MP(l, r)); } } if(can1) { REP(i, 0, (int)ind.size()) { a[ind[i]] = b[ind[i]]; } cout << a << "\n"; return 0; } else { char rpl = 'A'; for(char c = 'A'; c <= 'Z'; ++c) { if(a.find(c) == string::npos && b.find(c) == string::npos) { rpl = c; break; } } solve(a, b, helper, intervals, rpl); } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
A B |
correct output |
---|
A B |
user output |
---|
A B |
Test 2
Verdict: ACCEPTED
input |
---|
BABAZA BACBCB |
correct output |
---|
BABAZA BACACA BACBCB |
user output |
---|
BABAZA BACACA BACBCB |
Test 3
Verdict: ACCEPTED
input |
---|
AB BA |
correct output |
---|
AB CB CA BA |
user output |
---|
AB AC BC BA |
Test 4
Verdict: ACCEPTED
input |
---|
ABC BCD |
correct output |
---|
ABC DBD DCD BCD |
user output |
---|
ABC AEC BED BCD |
Test 5
Verdict: ACCEPTED
input |
---|
AXYB CXYD |
correct output |
---|
AXYB CXYD |
user output |
---|
AXYB CXYD |
Test 6
Verdict: ACCEPTED
input |
---|
LMIJLF PAQBMH |
correct output |
---|
LMIJLF PMQJMF PAQBMH |
user output |
---|
LMIJLF LAIBLH PAQBMH |
Test 7
Verdict: ACCEPTED
input |
---|
PNIWLSLIH CRLVPUFHD |
correct output |
---|
PNIWLSLIH CNLWPSFID CRLVPUFHD |
user output |
---|
PNIWLSLIH CNLWPSFID CRLVPUFHD |
Test 8
Verdict: ACCEPTED
input |
---|
ZDYIAVTKL ZJKVXGAUM |
correct output |
---|
ZDYIAVTKL ZJYVAGTUL ZJKVXGAUM |
user output |
---|
ZDYIAVTKL ZDKIXVAKM ZJKVXGAUM |
Test 9
Verdict: ACCEPTED
input |
---|
FBIXISJH NXZIESMG |
correct output |
---|
FBIXISJH NBZXESMH NXZIESMG |
user output |
---|
FBIXISJH NBZXESJG NXZIESMG |
Test 10
Verdict: ACCEPTED
input |
---|
OPGW QJIE |
correct output |
---|
OPGW QPIW QJIE |
user output |
---|
OPGW OJGE QJIE |
Test 11
Verdict: ACCEPTED
input |
---|
DUKNPKQZBL NZPBMOEBIC |
correct output |
---|
DUKNPKQZBL NUPNMKEZIL NZPBMOEBIC |
user output |
---|
DUKNPKQZBL NUPNMKEZIL NZPBMOEBIC |
Test 12
Verdict: ACCEPTED
input |
---|
ZWDTX HZOXI |
correct output |
---|
ZWDTX HWOTI HZOXI |
user output |
---|
ZWDTX HWOTI HZOXI |
Test 13
Verdict: ACCEPTED
input |
---|
URJF ITIQ |
correct output |
---|
URJF IRIF ITIQ |
user output |
---|
URJF UTJQ ITIQ |
Test 14
Verdict: ACCEPTED
input |
---|
WYWBWU IRYVBA |
correct output |
---|
WYWBWU WRWVWA IRYVBA |
user output |
---|
WYWBWU WRWVWA IRYVBA |