Submission #116593

#TimeUsernameProblemLanguageResultExecution timeMemory
116593JohnTitorMatch (CEOI16_match)C++11
0 / 100
2 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, j, k) for(int i=(j); i<=(k); i++) #define FFOR(i, j, k) for(int i=(j); i<(k); i++) #define DFOR(i, j, k) for(int i=(j); i>=(k); i--) #define bug(x) cerr<<#x<<" = "<<(x)<<'\n' #define pb push_back #define mp make_pair #define bit(s, i) (((s)>>(i))&1LL) #define mask(i) ((1LL<<(i))) #define builtin_popcount __builtin_popcountll #define __builtin_popcount __builtin_popcountll using ll=long long; using ld=long double; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2; template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;} template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);} template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);} template <typename T> inline void writeln(T x){write(x); putchar('\n');} #define taskname "Match" string s; int cnt[256]; string t; vector <char> v; int main(){ #ifdef Aria if(fopen(taskname".in", "r")) freopen(taskname".in", "r", stdin); #endif // Aria cin>>s; for(char c: s) cnt[c]++; FOR(c, 'a', 'z') if(cnt[c]%2){ puts("-1"); return 0; } for(char c: s){ if(v.empty()||(v.back()!=c)||cnt[c]){ v.pb(c); t+='('; cnt[c]-=2; if(cnt[c]<0){ puts("-1"); return 0; } } else{ v.pop_back(); t+=')'; } } cout<<t<<'\n'; }

Compilation message (stderr)

match.cpp: In function 'int main()':
match.cpp:30:25: warning: array subscript has type 'char' [-Wchar-subscripts]
     for(char c: s) cnt[c]++;
                         ^
match.cpp:36:43: warning: array subscript has type 'char' [-Wchar-subscripts]
         if(v.empty()||(v.back()!=c)||cnt[c]){
                                           ^
match.cpp:39:18: warning: array subscript has type 'char' [-Wchar-subscripts]
             cnt[c]-=2;
                  ^
match.cpp:40:21: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(cnt[c]<0){
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...