답안 #61978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61978 2018-07-27T07:17:47 Z alex(#2140) parentrises (BOI18_parentrises) C++11
0 / 100
4 ms 628 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

char arr[1000010];
char res[1000010];

void solve1()
{
    int n, i;
    scanf("%s", arr);

    n = strlen(arr);

    int c1, c2;
    c1 = c2 = 0;
    for(i = 0; i < n; i++)
    {
        if(arr[i] == '(')
        {
            res[i] = 'G';
            c1++;
        }
        else
        {
            if(c1 > 0)
            {
                res[i] = 'B';
                c1--;
                c2++;
            }
            else if(c2 > 0)
            {
                res[i] = 'R';
                c2--;
            }
            else
            {
                printf("impossible\n");
                return;
            }
        }
    }

    int t = 0;
    for(i = n - 1; i >= 0 && c2 > 0; i--)
    {
        if(arr[i] == '(')
        {
            if(t > 0)
            {
                t--;
                c2--;
                res[i] = 'B';
            }
        }
        else if(arr[i] == ')' && res[i] == 'B')
            t++;
    }

    if(c2 > 0)
    {
        printf("impossible\n");
        return;
    }

    int p = n - 1;
    for(i = n - 1; i >= 0 && c1 > 0; i--)
    {
        if(arr[i] == '(' && res[i] == 'G')
        {
            while(p > i && arr[p] != ')')
                p--;

            if(p <= i)
                continue;

            c1--;
            if(res[p] == 'B')
                res[i] = 'R';
            else
                res[i] = 'B';
            res[p--] = 'G';
        }
    }

    if(c1 > 0)
    {
        printf("impossible\n");
        return;
    }

    int t1, t2;
    t1 = t2 = 0;
    for(i = 0; i < n; i++)
    {
        if(arr[i] == '(')
        {
            if(res[i] != 'R')
                t1++;
            if(res[i] == 'B')
                t2++;
        }
        if(arr[i] == ')')
        {
            if(res[i] != 'R')
                t1--;
            if(res[i] == 'B')
                t2--;
        }
        assert(t1 >= 0 && t2 >= 0);
    }
    assert(t1 == 0 && t2 == 0);

    res[n] = '\0';
    printf("%s\n", res);
}

void solve2()
{
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int p, t, i;
    scanf("%d%d", &p, &t);
    for(i = 0; i < t; i++)
    {
        if(p == 1)
            solve1();
        else
            solve2();
    }
    return 0;
}

Compilation message

parentrises.cpp: In function 'void solve1()':
parentrises.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", arr);
     ~~~~~^~~~~~~~~~~
parentrises.cpp: In function 'int main()':
parentrises.cpp:144:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &p, &t);
     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 628 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 628 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 628 KB Unexpected end of file - int32 expected