Submission #578945

# Submission time Handle Problem Language Result Execution time Memory
578945 2022-06-18T08:28:36 Z FatihSolak parentrises (BOI18_parentrises) C++17
50 / 100
133 ms 8220 KB
#include <bits/stdc++.h>
#define N 105
using namespace std;
const int mod = 1e9 + 7;
int val[N];
int ans[N];
void solve1(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> r,rr,points;
    string ans = "";
    for(int i = 0;i<n;i++){
        ans += ".";
        if(s[i]  == '('){
            ans[i] = 'R';
            r.push_back(i);
            rr.push_back(i);
        }
        if(s[i] == ')'){
            if(rr.empty()){
                if(r.empty()){
                    cout << "impossible" << endl;
                    return;
                }
                ans[r.back()] = 'G';
                ans[i] = 'B';
                r.pop_back();
                continue;
            }
            rr.pop_back();
            points.push_back(i);
            ans[i] = 'R';
        }
    }
    if(points.size() < rr.size()){
        cout << "impossible" << endl;
        return;
    }
    for(int i = 0;i<rr.size();i++){
        ans[rr[i]] = 'B';
        ans[points[points.size() - rr.size() + i]] = 'G';
        if(rr[i] > points[points.size() - rr.size() + i]){
            cout << "impossible" << endl;
            return;
        }
    }
    cout << ans << endl;
}
void solve2(){
    int n;
    cin >> n;
    cout << (ans[n])%mod  << 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
    /*
    for(int i = 0;i*3<N;i++){
        int a = i,b = 2*i;
        vector<vector<int>> dp(N,vector<int>(N,0));
        dp[0][0] = 1;
        for(int i = 0;i<N;i++){
            for(int j = 0;j<N;j++){
                bool ok = 1;
                if(2*(i+1) < j)
                    ok = 0;
                if(i + 1 > a)
                    ok = 0;
                if(ok){
                    dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod;
                }
                ok = 1;
                if(2*i < j+1)
                    ok = 0;
                if(j + 1 > b)
                    ok = 0;
                if(ok){
                    dp[i][j+1] = (dp[i][j+1] + dp[i][j])%mod;
                }
            }
        }
        cout << dp[a][b] << endl;
        val[3*i] = dp[a][b];
    }
    for(int a = 1;a<N;a++){
        for(int b = 1;b<=2*a;b++){
            int br = a - b;
            vector<vector<int>> dp(a+1,vector<int>(b+1,0));
            dp[0][1] = 1;
            for(int i = 0;i<=a;i++){
                for(int j = 1;j<=b;j++){
                    bool ok = 1;
                    if(j < br && i == j+1)
                        ok = 0;
                    if(2*(a-i) < (b - j))
                        ok = 0;
                    if(i + 1 > a)
                        ok = 0;
                    if(ok){
                        dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod;
                    }
                    ok = 1;
                    if(2*(a-i) < (b - j))
                        ok = 0;
                    if(j + 1 > b)
                        ok = 0;
                    if(ok){
                        dp[i][j+1] = (dp[i][j+1] + dp[i][j])%mod;
                    }

                }
            }
            if(a + b == 7){
                cout << a << " " << b << " " << dp[a][b] << endl;
            }
            for(int i = 0;i<1;i++){
                if(i + a + b < N)
                    ans[i + a + b] = (ans[i+a+b] + (long long)val[i]*dp[a][b])%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:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0;i<rr.size();i++){
      |                   ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 312 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 13 ms 468 KB Output is correct
17 Correct 3 ms 1380 KB Output is correct
18 Correct 3 ms 572 KB Output is correct
19 Correct 3 ms 980 KB Output is correct
20 Correct 3 ms 1312 KB Output is correct
21 Correct 133 ms 1928 KB Output is correct
22 Correct 25 ms 8220 KB Output is correct
23 Correct 17 ms 2900 KB Output is correct
24 Correct 20 ms 4520 KB Output is correct
25 Correct 27 ms 8100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -