# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
175851 | 2020-01-07T11:32:15 Z | Ruxandra985 | Match (CEOI16_match) | C++14 | 2000 ms | 15368 KB |
#include <bits/stdc++.h> #pragma GCC optimize "Ofast" using namespace std; int sp[30][100010]; char sol[100010] , s[100010]; int ok; int stk[100010] , pre[30][100010]; int match (int st , int dr){ int i , elem = 0; if (st > dr) return 1; for (i=0;i<'z' - 'a';++i){ if (((sp[i][dr] - sp[i][st-1]) & 1) == 1) return 0; } for (i=st;i<=dr;++i){ if (stk[elem] == s[i]) elem--; else stk[++elem] = s[i]; } return (elem == 0); } void solve (int st , int dr){ int i; if (st > dr) return; if (!ok) /// nu mai are rost return; /// stii ca pe st pui ( , gaseste i match ul for (i = pre[s[st]][dr]; i >= st + 1 ; i = pre[s[st]][i-1]){ if (match(st + 1 , i - 1) && match(i + 1 , dr)) break; } if (i < st + 1){ ok = 0; return; } else { sol[st] = '('; sol[i] = ')'; solve(st + 1 , i - 1); solve (i + 1 , dr); } } int main() { FILE *fin = stdin; FILE *fout = stdout; int n , i; fgets (s+1 , 100010 , fin); n = 0; while ( 'a' <= s[n+1] && s[n+1] <= 'z' ){ n++; s[n]-='a'; for (i=0;i<='z'-'a';++i){ sp[i][n] = sp[i][n-1] + (s[n] == i); if (i == s[n]) pre[i][n] = n; else pre[i][n] = pre[i][n-1]; } } stk[0] = -1; ok = 1; solve (1 , n); if (ok == 0){ fprintf (fout,"-1"); } else { fputs (sol+1,fout); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 508 KB | Output is correct |
4 | Correct | 3 ms | 760 KB | Output is correct |
5 | Correct | 3 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 888 KB | Output is correct |
7 | Correct | 7 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 508 KB | Output is correct |
4 | Correct | 3 ms | 760 KB | Output is correct |
5 | Correct | 3 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 888 KB | Output is correct |
7 | Correct | 7 ms | 1016 KB | Output is correct |
8 | Correct | 14 ms | 1912 KB | Output is correct |
9 | Correct | 97 ms | 2112 KB | Output is correct |
10 | Correct | 21 ms | 2040 KB | Output is correct |
11 | Correct | 28 ms | 2044 KB | Output is correct |
12 | Correct | 1113 ms | 13324 KB | Output is correct |
13 | Correct | 1066 ms | 14220 KB | Output is correct |
14 | Execution timed out | 2050 ms | 15368 KB | Time limit exceeded |
15 | Halted | 0 ms | 0 KB | - |