Submission #745430

#TimeUsernameProblemLanguageResultExecution timeMemory
745430PredescuSebastianIonMatch (CEOI16_match)C++17
0 / 100
1 ms212 KiB
#include <fstream> #include <algorithm> #include <cmath> #include <cstring> #include <cstdlib> #include <cstdio> #include <iomanip> using namespace std; ifstream cin("match.in"); ofstream cout("match.out"); constexpr int nmax = 1e5 + 2; int n,v[nmax],frecv[nmax],deschis[nmax],nr; char s[nmax]; int main() { cin.getline((s + 1),nmax); int n = strlen(s + 1); for(int i = 1; i <= n; i++) { int ch = s[i] - '0' + 1; v[i] = ch; if(frecv[ch] == 0) { deschis[++nr] = ch; frecv[ch]++; } else { if(deschis[nr] == ch) { frecv[ch]--; nr--; } else { cout << "-1" << '\n'; return 0; } } } if(nr > 0) { cout << "-1" << '\n'; return 0; } for(int i = 1; i <= n; i++) { int ch = v[i]; if(frecv[ch] == 0) { int ci = i, cnt = 0; while(v[ci] == ch && ci <= n) { cnt++; ci++; } ci--; int j = 1; for(; j <= (cnt + 1) / 2; j++) { cout << "("; } for(; j <= cnt; j++) { cout << ")"; } i = ci; frecv[ch] = cnt % 2; } else { int ci = i, cnt = 0; while(v[ci] == ch && ci <= n) { cnt++; ci++; } ci--; int j = 1; for(; j <= cnt / 2; j++) { cout << "("; } for(; j <= cnt; j++) { cout << ")"; } i = ci; frecv[ch] = (1 + cnt) % 2; } } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...