답안 #578947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578947 2022-06-18T08:30:27 Z FatihSolak parentrises (BOI18_parentrises) C++17
50 / 100
125 ms 7260 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 = "";
    int a = 0,b = 0;
    for(int i = 0;i<n;i++){
        ans += ".";
        if(s[i] == '(')a++;
        else b++;
        if(2*a < b){
            cout << "impossible" << endl;
            return;
        }
        if(s[i]  == '('){
            ans[i] = 'R';
            r.push_back(i);
            rr.push_back(i);
        }
        if(s[i] == ')'){
            if(rr.empty()){
                ans[r.back()] = 'G';
                ans[i] = 'B';
                r.pop_back();
                continue;
            }
            rr.pop_back();
            points.push_back(i);
            ans[i] = 'R';
        }
    }
    if(2*b < a){
        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:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i = 0;i<rr.size();i++){
      |                   ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 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 340 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 15 ms 404 KB Output is correct
17 Correct 3 ms 1260 KB Output is correct
18 Correct 2 ms 464 KB Output is correct
19 Correct 3 ms 852 KB Output is correct
20 Correct 4 ms 1296 KB Output is correct
21 Correct 125 ms 1012 KB Output is correct
22 Correct 25 ms 7260 KB Output is correct
23 Correct 17 ms 2068 KB Output is correct
24 Correct 21 ms 3904 KB Output is correct
25 Correct 26 ms 7256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -