Submission #237365

#TimeUsernameProblemLanguageResultExecution timeMemory
237365VimmerRetro (COCI17_retro)C++14
0 / 100
256 ms524292 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define F first #define S second #define sz(x) int(x.size()) #define pb push_back #define N 100001 #define M ll(1e9 + 7) #define inf 1e9 + 1e9 using namespace std; //using namespace __gnu_pbds; typedef long double ld; typedef long long ll; typedef short int si; typedef array <int, 2> a2; //typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; vector <char> ans, dp[250][250][27][27]; char mk[250][250][27][27]; bool low(vector <char> &a, vector <char> &b) { for (register int i = 0; i < sz(a); i++) { if (a[i] == b[i]) continue; return a[i] == '('; } return 0; } int main() { //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout); ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; string s[n]; for (int i = 0; i < n; i++) cin >> s[i]; int sx, sy; for (int i = 0; i < m; i++) if (s[n - 1][i] == 'M') {sx = n - 1; sy = i; break;} mk[n - 1][sy][0][0] = 'z'; for (register int i = n - 1; i >= 0; i--) for (register int j = 0; j < m; j++) for (register int k = 0; k < min(27, n - i); k++) for (register int kr = 0; kr <= k; kr++) { if (mk[i][j][k][kr] != 'z') continue; if (k == kr && (k + kr > sz(ans) || (k + k == sz(ans) && low(dp[i][j][k][kr], ans)))) ans = dp[i][j][k][kr]; if (s[i][j] == '*' || i == 0) continue; for (register int a = -1; a <= 1; a++) if (a + j >= 0 && a + j < m && (k != kr || s[i - 1][j + a] != ')')) { int nw = kr, nk = k; vector <char> nr = dp[i][j][k][kr]; if (s[i - 1][j + a] == '(') {nr.pb('('); nk++;} if (s[i - 1][j + a] == ')') {nr.pb(')'); nw++;} if (mk[i - 1][j + a][nk][nw] != 'z' || low(nr, dp[i - 1][j + a][nk][nw])) {mk[i - 1][j + a][nk][nw] = 'z'; dp[i - 1][j + a][nk][nw] = nr;} } } cout << sz(ans) << endl; for (auto it : ans) cout << it; }

Compilation message (stderr)

retro.cpp: In function 'int main()':
retro.cpp:61:9: warning: variable 'sx' set but not used [-Wunused-but-set-variable]
     int sx, sy;
         ^~
retro.cpp:66:25: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
     mk[n - 1][sy][0][0] = 'z';
     ~~~~~~~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...