Submission #578752

#TimeUsernameProblemLanguageResultExecution timeMemory
578752FatihSolakparentrises (BOI18_parentrises)C++17
50 / 100
112 ms8336 KiB
#include <bits/stdc++.h> #define N 305 using namespace std; const int mod = 1e9 + 7; int dp[N][N][N][2][2]; int ans[N]; void solve1(){ string s; cin >> s; int n = s.size(); vector<int> r; vector<int> rr; int br = 0,bb = 0; string ans = ""; vector<int> points; for(int i = 0;i<n;i++){ ans += "."; if(s[i] == '('){ ans[i] = 'R'; br++; r.push_back(i); rr.push_back(i); } if(s[i] == ')'){ if(br + bb == 0){ if(r.empty()){ cout << "impossible" << endl; return; } ans[r.back()] = 'G'; r.pop_back(); bb++; } if(br >= bb){ rr.pop_back(); points.push_back(i); ans[i] = 'R'; br--; } else{ ans[i] = 'B'; bb--; } } } if(points.size() < br || rr.size() < br){ cout << "impossible" << endl; return; } for(int i = 0;i<br;i++){ ans[rr[i]] = 'B'; ans[points[points.size() - br + i]] = 'G'; if(rr[i] > points[points.size() - br + i]){ cout << "impossible" << endl; return; } } cout << ans << endl; } void solve2(){ int n; cin >> n; cout << ans[n] << endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif /* dp[0][0][0][0][0] = 1; for(int i = 0;i<N-2;i++){ for(int j = 0;j<N-2;j++){ for(int c = 0;c<=j;c++){ for(int d = 0;d<2;d++){ for(int e = 0;e<2;e++){ for(int f = 0;f<2;f++){ for(int g = 0;g<2;g++){ if(d == f && e > g)continue; int dx = (f == 0?g+1:0); int dy = (f == 1?g+1:0); dp[i+1][j+dx][c+dy][f][g] = (dp[i+1][j+dx][c+dy][f][g] + dp[i][j][c][d][e]) % mod; } } if(j == c){ if(i == 4 && dp[i][j][c][d][e]){ cout << i << " " << j << " " << c << " " << d << " " << e << " "<< dp[i][j][c][d][e] << endl; } ans[i] = (ans[i] + dp[i][j][c][d][e])%mod; } } } //dp[i+1][j+1][c] = (dp[i+1][j+1][c] + dp[i][j][c]) % mod; //dp[i+1][j+2][c] = (dp[i+1][j+2][c] + dp[i][j][c]) % mod; //dp[i+1][j][c+1] = (dp[i+1][j][c+1] + dp[i][j][c]) % mod; //dp[i+1][j][c+2] = (dp[i+1][j][c+2] + dp[i][j][c]) % mod; } } }*/ int type; cin >> type; int t=1; cin>>t; while(t--){ if(type == 1) solve1(); if(type ==2) solve2(); } #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }

Compilation message (stderr)

parentrises.cpp: In function 'void solve1()':
parentrises.cpp:46:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |     if(points.size() < br || rr.size() < br){
      |        ~~~~~~~~~~~~~~^~~~
parentrises.cpp:46:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |     if(points.size() < br || rr.size() < br){
      |                              ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...