Submission #148054

#TimeUsernameProblemLanguageResultExecution timeMemory
148054. (#201)Get Hundred Points! (FXCUP4_hundred)C++17
33 / 100
9 ms384 KiB
#include "hundred.h" #include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef pair<int,int> pii; const int N = 105; pii par[N]; bool Test (int A, int B, int C, string R, string T, int V) { int RA = 0, RB = 0, RC = 0; for(int i=0;i<A+B+C;i++) { if(R[i] == 'A') RA++; if(R[i] == 'B') RB++; if(R[i] == 'C') RC++; } if(A != RA || B != RB || C != RC) return false; int RV = 0; for(int i=0;i<A+B+C;i++) { if(R[i] == T[i]) RV++; } return (V == RV); } string GetHundredPoints(int _A, int _B, int _C) { int cnt[3] = {_A, _B, _C}; string def; for(int i=0;i<3;i++) { if(!cnt[i]) continue; def.push_back('A'+i); cnt[i]--; } for(int i=0;i<3;i++) { while(cnt[i]--) { def.push_back('A'+i); } } int dv = Mark(def); for(int i=_A+_B+_C-1;i;i--) { int j; for(j=0;def[i]==def[j];j++); swap(def[i], def[j]); int T = Mark(def); swap(def[i], def[j]); par[i] = {j, T - dv}; } for(int k=0;k<3;k++) { string R; R.push_back('A'+k); bool mosun = false; for(int i=1;i<_A+_B+_C;i++) { int P, Q; tie(P, Q) = par[i]; char A = def[P], B = def[i]; char C = (3*'A'+3) - ((int)A + B); if(Q == 2) { if(R[P] != B) {mosun = true; break;} R.push_back(A); } else if(Q == 1) { if(R[P] == B) R.push_back(C); else if(R[P] == C) R.push_back(A); else {mosun = true; break;} } else if(Q == 0) { R.push_back(R[P]); } else if(Q == -1) { if(R[P] == A) R.push_back(C); else if(R[P] == C) R.push_back(B); else {mosun = true; break;} } else if(Q == -2) { if(R[P] != A) {mosun = true; break;} R.push_back(B); } else {mosun = true; break;} } if(mosun) continue; if(Test(_A, _B, _C, R, def, dv)) return R; } return ""; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...