QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644692#8544. Colorful Graph 2asaltfishWA 57ms3584kbC++232.3kb2024-10-16 15:07:582024-10-16 15:07:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 15:07:59]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:3584kb
  • [2024-10-16 15:07:58]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<numeric>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll               long long
#define endl             "\n"
using namespace std;
inline int read() { register int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-')w = -1; ch = getchar(); }while (ch >= '0' && ch <= '9')s = s * 10 + ch - '0', ch = getchar(); return s * w; }
ll t, n, m, l, r;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        if (!m)
        {
            ll now = 0;
            for (int i = 0; i < n; i++)
            {
                cout << (now ? 'R' : 'B');
                now = 1 - now;
            }
            cout << endl;
            continue;
        }
        vector<char>ans(n, '0');
        vector<pair<int, int>>vt;
        set<int>st;
        for (int i = 1; i <= m; i++)
        {
            cin >> l >> r;
            st.insert(l);
            st.insert(r);
            //if (r > l)swap(l, r);
            //vt.push_back({ l,r });
        }
        char last = 'R';
        for (auto i : st)
        {
            ans[i] = (last == 'R' ? 'B' : 'R');
            last = ans[i];
        }
        //sort(vt.begin(), vt.end());
        //for (int i = 0; i < m; i++)
        //{
        //    l = vt[i].first;
        //    r = vt[i].second;
        //    if (ans[l] == '0' && ans[r] == '0')
        //    {
        //        ans[l] = 'R';
        //        ans[r] = 'B';
        //    }
        //    else if (ans[l] != '0')
        //    {
        //        ans[r] = (ans[l] == 'B' ? 'R' : 'B');
        //    }
        //    else if (ans[r] != '0')
        //    {
        //        ans[l] = (ans[r] == 'B' ? 'R' : 'B');
        //    }
        //}
        char p;
        int i = *(st.begin()), sum = 1;
        for (;sum<=n; i=(i+1)%n)
        {
            sum++;
            if (ans[i] == '0')
            {
                ans[i] = (p == 'R' ? 'B' : 'R');
            }
            p = ans[i];
        }
        for (int i = 0; i < n; i++)
            cout << ans[i];
        cout << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

input:

3
3 0
4 1
1 3
6 3
0 2
2 4
4 0

output:

BRB
BBRR
BRRBBR

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 57ms
memory: 3584kb

input:

100000
9 6
2 0
4 6
3 6
0 6
0 7
2 6
3 0
5 2
2 4
2 0
6 3
1 5
4 1
2 4
9 6
3 1
6 4
8 1
3 6
1 6
8 6
3 0
7 4
3 0
4 0
6 4
3 1
7 4
5 1
5 0
3 1
1 4
4 1
1 3
6 3
2 4
4 0
2 0
6 3
3 0
1 3
5 3
7 4
0 5
2 5
5 1
3 5
8 5
4 1
5 1
5 0
1 3
5 7
3 0
8 5
0 2
4 6
0 6
0 3
4 0
8 5
5 1
1 4
5 0
3 1
5 7
3 0
10 7
0 2
9 2
5 8
3 9
...

output:

BRRBRBBRB
BRB
BRRBB
BBRBBR
RBRRBRRBB
BRB
BRBBRBB
BRBBRBR
BBRR
BRRBBR
BRBBRR
BRBRBBR
BRBBRBRR
BRB
BRRBRBBR
BRBBRBRR
BRB
BRRBRBRBBR
RBRRBRRB
BBRBRBRRBR
BBRBRBBRBR
BRRBRBBRBB
BRB
BBRBBRR
BBRRBR
BRRBBRBR
BBRR
BRRBRRB
BBRBRBBRBR
RBRBRRB
RBRBBRRB
BBRRBR
BRRBBR
BRB
BRB
BBRRBRRBR
BRBRRBB
BRBBR
RBRBRRBRRB
BR...

result:

wrong answer cycle detected (test case 22)