Submission #578752

# Submission time Handle Problem Language Result Execution time Memory
578752 2022-06-17T20:34:25 Z FatihSolak parentrises (BOI18_parentrises) C++17
50 / 100
112 ms 8336 KB
#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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 19 ms 484 KB Output is correct
17 Correct 3 ms 1352 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 3 ms 980 KB Output is correct
20 Correct 4 ms 1356 KB Output is correct
21 Correct 112 ms 2092 KB Output is correct
22 Correct 24 ms 8336 KB Output is correct
23 Correct 18 ms 3060 KB Output is correct
24 Correct 21 ms 4608 KB Output is correct
25 Correct 24 ms 8296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -