# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
135801 |
2019-07-24T11:33:17 Z |
neki |
Match (CEOI16_match) |
C++14 |
|
2 ms |
256 KB |
#include <bits/stdc++.h>
#define loop(i, a, b) for(int i=a;i<b;i++)
#define cc(a) cout<< a << endl;
#define maxn 100100
using namespace std;
int sums[maxn][27];
vector<int> crke[27];
vector<int> zap;
bool neki[27], skip[maxn];
bool check(int i, int j){
loop(c, 0, 27) if((sums[i][c]-sums[j-1][c])%2==1) return false;
return true;
}
int main() {
int n;cin >> n;
char temp;
loop(i, 0, n){
scanf(" %c ", &temp);temp-='a';
zap.push_back(temp);
crke[temp].push_back(i);
sums[i][temp]++;
loop(c, 0, 27) sums[i+1][c]=sums[i][c];
}
vector<char> ans;ans.resize(n);
loop(i, 0, n){
if(skip[i]) ans[i]=')';
else if(check(i, crke[zap[i]][crke[zap[i]].size()-1])){
ans[i]='(';
skip[crke[zap[i]][crke[zap[i]].size()-1]]=1;
if(crke[zap[i]].size()<2){
cc(-1);
return 0;
}
crke[zap[i]].pop_back();
crke[zap[i]].erase(crke[zap[i]].begin());
}
else ans[i]=')';
}
loop(i, 0, n) cout << ans[i];
}
Compilation message
match.cpp: In function 'int main()':
match.cpp:23:15: warning: array subscript has type 'char' [-Wchar-subscripts]
crke[temp].push_back(i);
^
match.cpp:24:18: warning: array subscript has type 'char' [-Wchar-subscripts]
sums[i][temp]++;
^
match.cpp:21:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c ", &temp);temp-='a';
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |