QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233628#7636. Fair Electionsucup-team296WA 1ms3852kbC++142.2kb2023-10-31 20:33:352023-10-31 20:33:35

Judging History

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

  • [2023-10-31 20:33:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3852kb
  • [2023-10-31 20:33:35]
  • 提交

answer

#include <bits/stdc++.h>

#define long long long int
#define DEBUG
using namespace std;

// @author: pashka

vector<vector<int>> d;

bool interesting(int i, int j) {
    if (d[i + 1][j] != d[i][j]) return true;
    if (d[i][j + 1] != d[i][j]) return true;
    return false;
}

void print() {
    for (auto &a : d) {
        for (auto x : a) {
            cout << x << " ";
        }
        cout << "\n";
    }
    cout << "\n";
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }

    d.assign(n + 2, vector<int>(n + 2, -1));
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            int k = n - i - j;
            if (k >= 0 && k <= n) {
                if (i >= j && i >= k) {
                    d[i][j] = 0;
                } else if (j >= k) {
                    d[i][j] = 1;
                } else {
                    d[i][j] = 2;
                }
            }
        }
    }

    vector<pair<int, int>> fr;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (d[i][j] == -1) continue;
            if (interesting(i, j)) fr.push_back({i, j});
        }
    }


//    print();

    for (int t = n - 1; t >= 0; t--) {
        sort(fr.begin(), fr.end());
        fr.erase(unique(fr.begin(), fr.end()), fr.end());
        vector<pair<int, int>> nfr;

        for (auto [i, j] : fr) {
            int r = -1;
            for (int x : a[t]) {
                if (d[i][j + 1] == x || d[i + 1][j] == x || d[i][j] == x) {
                    r = x;
                    break;
                }
            }
            if (r != d[i][j]) {
                d[i][j] = r;
                if (interesting(i, j)) nfr.push_back({i, j});
                if (i > 0 && interesting(i - 1, j)) nfr.push_back({i - 1, j});
                if (j > 0 && interesting(i, j - 1)) nfr.push_back({i, j - 1});
            }
        }

        fr = nfr;
//        print();
    }
    cout << d[0][0] + 1 << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3684kb

input:

3
3 2 1
1 2 3
2 1 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

5
1 2 3
2 3 1
1 3 2
3 1 2
2 1 3

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3852kb

input:

5
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1

output:

3

result:

wrong answer 1st numbers differ - expected: '1', found: '3'