QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#413297#8680. Turning RedsupepapupuWA 125ms38564kbC++202.4kb2024-05-17 11:30:562024-05-17 11:30:57

Judging History

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

  • [2024-05-17 11:30:57]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:38564kb
  • [2024-05-17 11:30:56]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 2e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;

bool st[N * 3];
int n, m, ans, cnt;
int c[N], cur[N];
vector<int> l[N], b[N * 2], used;

void dfs(int u) {
    used.emplace_back(u);
    st[u] = 1;
    for (int v: l[u]) {
        if (st[v + n]) continue;
        used.emplace_back(v + n);
        st[v + n] = 1;
        int t = (3 - cur[u]) % 3;
        cnt += t;
        for (int i: b[v]) cur[i] = (cur[i] + t) % 3;
        for (int i: b[v]) 
            if (i != u) 
                dfs(i);
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    string s; cin >> s;
    for (int i = 0; i < n; ++i) 
        if (s[i] == 'G') c[i + 1] = cur[i + 1] = 1;
        else if (s[i] == 'B') c[i + 1] = cur[i + 1] = 2;
    for (int i = 1; i <= m; ++i) {
        int sz; cin >> sz;
        b[i].resize(sz);
        for (int j = 0; j < sz; ++j) {
            cin >> b[i][j];
            l[b[i][j]].emplace_back(i);
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (st[i]) continue;
        if (l[i].empty()) {
            if (c[i]) 
                return cout << "impossible\n", 0;
            continue;
        }
        if (l[i].size() == 1) {
            cnt = 0;
            dfs(i);
            ans += cnt;
            for (int j: used) 
                if (j <= n && cur[j]) 
                    return cout << "impossible\n", 0;
            used.clear();
            continue;
        }
        int mn = INF, e = l[i][0];
        vector<int> vec;
        for (int j = 0; j < 3; ++j) {
            cnt = j;
            for (int u: b[e]) cur[u] = (cur[u] + j) % 3;
            used.emplace_back(e + n);
            dfs(i);
            for (int u: used) {
                if (u <= n) {
                    if (cur[u]) cnt = INF;
                    cur[u] = c[u];
                }
                else st[u] = 0;
            }
            if (cnt < mn) mn = cnt, vec = move(used);
            used.clear();
        }
        if (mn == INF) return cout << "impossible\n", 0;
        for (int i: vec) 
            if (i <= n) st[i] = 1;
        ans += mn;
    }
    cout << ans << el;
}

详细

Test #1:

score: 100
Accepted
time: 125ms
memory: 32088kb

input:

200000 171004
RGRGBBBGGBRRRBBRRBRBBGRRRGGGGRRRRGBBBRGGGBGGRGGRGRRBRBRRGGBGGGGBRBRBRRBRBRGRRGRBRRBGRRRRBRBBBRGBBBGRRBRGRRGGRGGBGRBGRBRGBBRRBBBGBGRGBBRBGGGGBBBBRBRRRGBGRRBBGGGRRBRBBRGRBGRBRGGBRBBBBRGGRRRBGRBGRBRRRGRGRRBRGRRGRRGBBBBRGGBBRRBGGBGBGRBRGBGGRRGRBRRGGRGRBBBRRBBRRGGRRRRGBRGGGGGGRGBRGRBBBGRBBG...

output:

impossible

result:

ok single line: 'impossible'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

10 0
RRRRRRRRRR

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

10 0
GGGGGGGGGG

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5652kb

input:

10 0
BBBBBBBBBB

output:

impossible

result:

ok single line: 'impossible'

Test #5:

score: 0
Accepted
time: 2ms
memory: 7696kb

input:

10 0
RGBRGBRGBR

output:

impossible

result:

ok single line: 'impossible'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5880kb

input:

10 0
GBBRRRBRGB

output:

impossible

result:

ok single line: 'impossible'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5588kb

input:

10 2
BBRRBRBRRR
7 7 8 5 3 10 9 4
5 6 10 1 3 2

output:

impossible

result:

ok single line: 'impossible'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5884kb

input:

10 9
RRRRRBGRRG
1 10
5 9 3 8 2 5
2 8 7
1 7
1 10
2 6 1
1 3
1 6
4 1 9 4 2

output:

5

result:

ok single line: '5'

Test #9:

score: 0
Accepted
time: 68ms
memory: 21012kb

input:

200000 10000
RBBBBGRRGGRBRGRGBBRBGGRGRGRBBRRRGRGRGRBGRBBBBGBGBBGGBBGGGGBRGBBBBBBRRGBBGGGRBBBGBRGGGRRGGGGBGBGBGRBBGGRRRGGGRGGRBRRBGRGRBBGBGGRGBBRBBBGGRGBBGBBBBBGRGBGGRGBGGBGRRBGBBGRBGBGGRBBBGBBBGGGBBBRBBGRRRBGBBRBRBBGRGGGBBRGRRRGRRRRGRRBGBRRRRGBBRBBGRRRRBRBRRRGBGRGGBGRBRBGBBRRGBBRBBBGBGGGBBRGRBRRGBBR...

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: 0
Accepted
time: 86ms
memory: 25024kb

input:

200000 49974
GRBRRGBRRRRRGBRBGRRBGGGRRRRBGGBBBGRRGBBRBGBRBRRBRBBRGRBGGBBGBBRRRBGGBRBRRGBRRRBRRGRGRGRBGRBGBBBGGGRGRBGRGGRBBRBRGGBRBBRRGGGRBGBGBGRBRBRGGBBBRBBRGRRBBGBGRBBRBBBRGGGGRRBGBBRGBGBGGBRBGGRGGGBRRRBBBGRRRRGBBBGBBGRRRBGRGGGRGBRGBGRBBRBRRBGGRGBBRGBBBRGRBBBRRGGRRRGGRRRGRRBGGGBGRRGBRRRRRGRGBGGRRRR...

output:

impossible

result:

ok single line: 'impossible'

Test #11:

score: 0
Accepted
time: 112ms
memory: 29176kb

input:

200000 97963
GRBBRBGGGBGBBGRBBBRGRGBBBGBRBGBGGGBRBBGRGRRBRRGBRRBBGRRGBRRGBBRBGRRRGRGRRRBGBBRGGBRRBBBGRBBGBBRRRGRRGRGRRRBBRGBRRRRRGGGGGBGRRBGRGGBBBBRBBRBBBBBBRRRGBGGRGRGRBBRRBGBRRBBRGBGRBRBRGBRRGBRBGGRGGGGBGGGRBBRGRGGBBGRRGRBGGRBGRBBBRRGGRGGBRRBBRGGRBRBBGRRRGGGBRBRGBRBRBBGGBRGRBBRGGBBBGGBGRRRRRRGGGBR...

output:

impossible

result:

ok single line: 'impossible'

Test #12:

score: 0
Accepted
time: 72ms
memory: 38564kb

input:

200000 400000
GRGBBBRRGGRGBBRBBGBRRRBBRBRGRGRRBBRBRGRBRGGRRGGBRGRRBRBRRBRRGGBBGRBBGRRRBRBGBBRBGBRBBBBBBGBRGRBBGRGBGBBGRGBGBBBBGRGRRRGGGBGGGGRBRBRBRRBGGBGRRGBGGGRRBBBGRBRBGGBBRBBGRGGBGRGBGRRGGBRGGRGRGGBGBRBBBRGGBRRRRBGRBGRRGBRBRGRRBBGGGRRGRGGBRBBBBRGBBGRGGBGGRBGGRBRBBRBBBGRGGGGGBGGRRBBGRGGGRGBRBGGGGR...

output:

200051

result:

ok single line: '200051'

Test #13:

score: -100
Wrong Answer
time: 1ms
memory: 5628kb

input:

10 10
GRBBGBBRRG
2 10 1
2 9 10
2 5 6
2 4 2
2 8 4
2 7 5
2 2 3
2 3 7
2 6 9
1 1

output:

impossible

result:

wrong answer 1st lines differ - expected: '12', found: 'impossible'