QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#230711#7636. Fair Electionsucup-team1191#WA 0ms3892kbC++204.1kb2023-10-28 20:26:392023-10-28 20:26:40

Judging History

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

  • [2023-10-28 20:26:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3892kb
  • [2023-10-28 20:26:39]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

const int M = 1e4 + 239;

int len[2][M][3];
int p[M][3];

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> p[i][j];
            p[i][j]--;
        }
    }

    memset(len[n & 1], 0, sizeof(len[n & 1]));
    for (int a = 0; a <= n; a++) {
        for (int b = 0; b <= n - a; b++) {
            int c = n - a - b;
            if (b > a && b >= c) {
                len[n & 1][a][1]++;
            } else if (c > a && c > b) {
                len[n & 1][a][2]++;
            } else {
                len[n & 1][a][0]++;
            }
        }
    }

    auto get_seg = [&](int sm, int a, int i) -> pair<int, int> {
        if (len[sm & 1][a] == 0) {
            return {-1, -1};
        }
        if (i == 0) {
            return {len[sm & 1][a][2], len[sm & 1][a][2] + len[sm & 1][a][0] - 1};
        } else if (i == 2) {
            return {0, len[sm & 1][a][2] - 1};
        } else {
            return {len[sm & 1][a][0] + len[sm & 1][a][2], len[sm & 1][a][0] + len[sm & 1][a][2] + len[sm & 1][a][1] - 1};
        }
    };

    auto getlen = [&](const pair<int, int>& v) -> int {
        if (v == make_pair(-1, -1)) {
            return 0;
        }
        return v.second - v.first + 1;
    };

    //auto uni = [&](const pair<int, int>& v1, const pair<int, int>& v2) -> int {
    auto uni = [&](pair<int, int> v1, pair<int, int> v2) -> int {
            if (v1 == make_pair(-1, -1)) {
            return getlen(v2);
        }
        if (v2 == make_pair(-1, -1)) {
            return getlen(v1);
        }
        if (v1 > v2) {
            swap(v1, v2);
        }
        assert(v1.second + 1 >= v2.first);
        return max(v1.second, v2.second) - min(v1.first, v2.first) + 1;
    };

    auto inter = [&](const pair<int, int>& v1, const pair<int, int>& v2) -> int {
        if (v1 == make_pair(-1, -1) || v2 == make_pair(-1, -1)) {
            return 0;
        }
        int L = max(v1.first, v2.first);
        int R = min(v1.second, v2.second);
        if (L <= R) {
            return R - L + 1;
        }
        return 0;
    };

    for (int sm = n - 1; sm >= 0; sm--) {
        memset(len[sm & 1], 0, sizeof(len[sm & 1]));

        for (int a = 0; a <= sm; a++) {
            {
                auto s1 = get_seg(sm + 1, a + 1, p[sm][0]);
                auto s2 = get_seg(sm + 1, a, p[sm][0]);
                if (s2 != make_pair(-1, -1)) {
                    if (s2.first > 0) {
                        s2.first--;
                    }
                    s2.second = min(s2.second, sm - a);
                }
                //cerr << s1.first << " " << s1.second << " " << s2.first << " " << s2.second << "\n";
                len[sm & 1][a][p[sm][0]] = uni(s1, s2);
            }

            {
                auto s1 = get_seg(sm + 1, a + 1, p[sm][2]);
                auto s2 = get_seg(sm + 1, a, p[sm][2]);
                if (s2 != make_pair(-1, -1)) {
                    if (s2.first == s2.second) {
                        s2 = {-1, -1};
                    } else {
                        s2.second--;
                    }
                }
                len[sm & 1][a][p[sm][2]] = inter(s1, s2);
            }

            len[sm & 1][a][p[sm][1]] = sm - a + 1 - len[sm & 1][a][p[sm][0]] - len[sm & 1][a][p[sm][2]];

            /*cerr << sm << " " << a << ": ";
            cerr << len[sm & 1][a][0] << " ";
            cerr << len[sm & 1][a][1] << " ";
            cerr << len[sm & 1][a][2] << "\n";*/
        }
    }

    for (int ans = 0; ans < 3; ans++) {
        if (len[0][0][ans] > 0) {
            cout << ans + 1 << "\n";
            return;
        }
    }
}

int main() {
#ifdef ONPC
    freopen("input", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 0ms
memory: 3884kb

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: -100
Wrong Answer
time: 0ms
memory: 3892kb

input:

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

output:

3

result:

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