QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233669#7636. Fair Electionsucup-team296TL 1ms3488kbC++142.7kb2023-10-31 21:09:132023-10-31 21:09:14

Judging History

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

  • [2023-10-31 21:09:14]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3488kb
  • [2023-10-31 21:09:13]
  • 提交

answer

#include <bits/stdc++.h>

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

// @author: pashka

vector<vector<int>> d;
vector<vector<int>> z;

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));
    z.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--) {
        vector<pair<int, int>> nfr;

        vector<pair<pair<int, int>, int>> ch;

        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;
                }
            }
            ch.push_back({{i, j}, r});
            int rr = d[i][j];
            d[i][j] = r;
            if (i > 0 && z[i - 1][j] != t && interesting(i - 1, j)) {
                nfr.push_back({i - 1, j});
                z[i - 1][j] = t;
            };
            if (j > 0 && z[i][j - 1] != t && interesting(i, j - 1)) {
                nfr.push_back({i, j - 1});
                z[i][j - 1] = t;
            }
            if (z[i][j] != t && interesting(i, j)) {
                nfr.push_back({i, j});
                z[i][j] = t;
            };
            d[i][j] = rr;
        }
        for (auto [p, r]: ch) {
            auto [i, j] = p;
            d[i][j] = r;
        }

        fr = nfr;
        assert(fr.size() <= 50000);
//        cout << fr.size() << "\n";
//        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: 0ms
memory: 3392kb

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: 3456kb

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: 0
Accepted
time: 1ms
memory: 3388kb

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

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

output:

3

result:

ok 1 number(s): "3"

Test #6:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

input:

20
1 2 3
2 3 1
1 3 2
3 1 2
2 1 3
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1
3 2 1
3 1 2
2 3 1
1 2 3
2 1 3
3 2 1
3 2 1
1 3 2
1 3 2
3 2 1

output:

1

result:

ok 1 number(s): "1"

Test #8:

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

input:

20
3 2 1
3 1 2
1 2 3
1 3 2
1 3 2
1 2 3
3 1 2
1 3 2
3 2 1
1 3 2
2 1 3
3 1 2
2 3 1
2 1 3
2 3 1
3 1 2
3 1 2
2 1 3
3 1 2
1 2 3

output:

1

result:

ok 1 number(s): "1"

Test #9:

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

input:

20
1 2 3
2 3 1
2 1 3
2 1 3
1 3 2
3 1 2
2 3 1
1 3 2
3 1 2
1 2 3
1 2 3
3 2 1
3 1 2
1 2 3
3 2 1
1 2 3
2 3 1
3 1 2
3 2 1
3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #10:

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

input:

20
3 1 2
3 2 1
1 2 3
1 3 2
1 3 2
2 3 1
1 3 2
2 3 1
1 2 3
3 2 1
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1
2 3 1
2 3 1
1 2 3
2 1 3
2 1 3

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

20
2 1 3
2 1 3
3 1 2
3 2 1
2 1 3
1 2 3
2 3 1
3 1 2
3 1 2
2 3 1
3 2 1
1 3 2
2 1 3
2 1 3
1 2 3
2 3 1
2 3 1
3 2 1
2 1 3
1 3 2

output:

2

result:

ok 1 number(s): "2"

Test #12:

score: -100
Time Limit Exceeded

input:

10000
1 2 3
2 3 1
1 3 2
3 1 2
2 1 3
1 2 3
3 2 1
1 2 3
1 2 3
3 2 1
3 2 1
3 1 2
2 3 1
1 2 3
2 1 3
3 2 1
3 2 1
1 3 2
1 3 2
3 2 1
3 2 1
3 1 2
1 2 3
1 3 2
1 3 2
1 2 3
3 1 2
1 3 2
3 2 1
1 3 2
2 1 3
3 1 2
2 3 1
2 1 3
2 3 1
3 1 2
3 1 2
2 1 3
3 1 2
1 2 3
1 2 3
2 3 1
2 1 3
2 1 3
1 3 2
3 1 2
2 3 1
1 3 2
3 1 2
...

output:


result: