Submission #952204

# Submission time Handle Problem Language Result Execution time Memory
952204 2024-03-23T09:35:59 Z arbuzick Ancient Machine 2 (JOI23_ancient2) C++17
94 / 100
448 ms 1072 KB
#include "ancient2.h"

#include <bits/stdc++.h>

using namespace std;

bitset<1001> bs[1000];

bool is_answer(int pos, int n) {
    for (int i = 0; i < pos; ++i) {
        for (int j = 0; j < n; ++j) {
            if (bs[i][j]) {
                if (bs[pos][j]) {
                    bs[pos] ^= bs[i];
                }
                break;
            }
        }
    }
    for (int j = 0; j < n; ++j) {
        if (bs[pos][j]) {
            for (int i = 0; i < pos; ++i) {
                if (bs[i][j]) {
                    bs[i] ^= bs[pos];
                }
            }
            return true;
        }
    }
    return false;
}

string get_answer(int n) {
    string ans = "";
    for (int i = 0; i < n; ++i) {
        int pos = -1;
        for (int j = i; j < n; ++j) {
            if (bs[j][i]) {
                pos = j;
                break;
            }
        }
        swap(bs[i], bs[pos]);
        for (int j = 0; j < n; ++j) {
            if (j != i && bs[j][i]) {
                bs[j] ^= bs[i];
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        ans += '0' + bs[i][n];
    }
    return ans;
}

string Solve(int n) {
    vector<pair<int, int>> qs;
    for (int a = 0; a < n; ++a) {
        for (int b = 1; b <= n; ++b) {
            if (a + b * 2 <= 130) {
                for (int i = 0; i < n; ++i) {
                    if (i >= a && i % b == a % b) {
                        bs[qs.size()][i] = 1;
                    } else {
                        bs[qs.size()][i] = 0;
                    }
                }
                if (is_answer(qs.size(), n)) {
                    qs.emplace_back(a, b);
                }
            }
            if (qs.size() == n) {
                break;
            }
        }
        if (qs.size() == n) {
            break;
        }
    }
    if (qs.size() != n) {
        return "";
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (j >= qs[i].first && j % qs[i].second == qs[i].first % qs[i].second) {
                bs[i][j] = 1;
            } else {
                bs[i][j] = 0;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        vector<int> a(qs[i].first + qs[i].second * 2), b(qs[i].first + qs[i].second * 2);
        for (int j = 0; j < qs[i].first; ++j) {
            a[j] = b[j] = j + 1;
        }
        for (int j = 0; j < qs[i].second; ++j) {
            if (j + 1 == qs[i].second) {
                a[qs[i].first + j] = b[qs[i].first + j] = qs[i].first;
                a[qs[i].first + qs[i].second + j] = b[qs[i].first + qs[i].second + j] = qs[i].first + qs[i].second;
            } else {
                a[qs[i].first + j] = b[qs[i].first + j] = qs[i].first + j + 1;
                a[qs[i].first + qs[i].second + j] = b[qs[i].first + qs[i].second + j] = qs[i].first + qs[i].second + j + 1;
            }
        }
        b[qs[i].first] = qs[i].first + qs[i].second + 1;
        b[qs[i].first + qs[i].second] = qs[i].first + 1;
        if (qs[i].second == 1) {
            b[qs[i].first]--;
            b[qs[i].first + qs[i].second]--;
        }
        int val = Query(qs[i].first + qs[i].second * 2, a, b);
        if (val < qs[i].first + qs[i].second) {
            bs[i][n] = 0;
        } else {
            bs[i][n] = 1;
        }
    }
    return get_answer(n);
}

Compilation message

ancient2.cpp: In function 'std::string Solve(int)':
ancient2.cpp:72:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |             if (qs.size() == n) {
      |                 ~~~~~~~~~~^~~~
ancient2.cpp:76:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |         if (qs.size() == n) {
      |             ~~~~~~~~~~^~~~
ancient2.cpp:80:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |     if (qs.size() != n) {
      |         ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Partially correct 433 ms 580 KB Output is partially correct
2 Partially correct 426 ms 820 KB Output is partially correct
3 Partially correct 425 ms 580 KB Output is partially correct
4 Partially correct 431 ms 624 KB Output is partially correct
5 Partially correct 424 ms 824 KB Output is partially correct
6 Partially correct 432 ms 636 KB Output is partially correct
7 Partially correct 422 ms 832 KB Output is partially correct
8 Partially correct 423 ms 580 KB Output is partially correct
9 Partially correct 429 ms 628 KB Output is partially correct
10 Partially correct 434 ms 1072 KB Output is partially correct
11 Partially correct 435 ms 848 KB Output is partially correct
12 Partially correct 425 ms 584 KB Output is partially correct
13 Partially correct 427 ms 828 KB Output is partially correct
14 Partially correct 431 ms 784 KB Output is partially correct
15 Partially correct 426 ms 580 KB Output is partially correct
16 Partially correct 426 ms 1012 KB Output is partially correct
17 Partially correct 425 ms 828 KB Output is partially correct
18 Partially correct 424 ms 576 KB Output is partially correct
19 Partially correct 430 ms 1036 KB Output is partially correct
20 Partially correct 422 ms 596 KB Output is partially correct
21 Partially correct 437 ms 848 KB Output is partially correct
22 Partially correct 428 ms 580 KB Output is partially correct
23 Partially correct 424 ms 580 KB Output is partially correct
24 Partially correct 429 ms 780 KB Output is partially correct
25 Partially correct 424 ms 884 KB Output is partially correct
26 Partially correct 426 ms 580 KB Output is partially correct
27 Partially correct 428 ms 576 KB Output is partially correct
28 Partially correct 424 ms 848 KB Output is partially correct
29 Partially correct 424 ms 812 KB Output is partially correct
30 Partially correct 423 ms 580 KB Output is partially correct
31 Partially correct 431 ms 768 KB Output is partially correct
32 Partially correct 431 ms 580 KB Output is partially correct
33 Partially correct 432 ms 580 KB Output is partially correct
34 Partially correct 430 ms 824 KB Output is partially correct
35 Partially correct 422 ms 1072 KB Output is partially correct
36 Partially correct 435 ms 584 KB Output is partially correct
37 Partially correct 425 ms 584 KB Output is partially correct
38 Partially correct 426 ms 848 KB Output is partially correct
39 Partially correct 425 ms 824 KB Output is partially correct
40 Partially correct 427 ms 580 KB Output is partially correct
41 Partially correct 428 ms 580 KB Output is partially correct
42 Partially correct 422 ms 836 KB Output is partially correct
43 Partially correct 425 ms 848 KB Output is partially correct
44 Partially correct 424 ms 828 KB Output is partially correct
45 Partially correct 425 ms 576 KB Output is partially correct
46 Partially correct 428 ms 828 KB Output is partially correct
47 Partially correct 425 ms 584 KB Output is partially correct
48 Partially correct 427 ms 832 KB Output is partially correct
49 Partially correct 429 ms 828 KB Output is partially correct
50 Partially correct 420 ms 576 KB Output is partially correct
51 Partially correct 448 ms 1040 KB Output is partially correct
52 Partially correct 436 ms 1008 KB Output is partially correct
53 Partially correct 422 ms 1044 KB Output is partially correct
54 Partially correct 423 ms 580 KB Output is partially correct
55 Partially correct 424 ms 580 KB Output is partially correct
56 Partially correct 425 ms 1072 KB Output is partially correct
57 Partially correct 426 ms 832 KB Output is partially correct
58 Partially correct 428 ms 604 KB Output is partially correct
59 Partially correct 426 ms 576 KB Output is partially correct
60 Partially correct 422 ms 816 KB Output is partially correct
61 Partially correct 436 ms 976 KB Output is partially correct
62 Partially correct 422 ms 580 KB Output is partially correct
63 Partially correct 427 ms 832 KB Output is partially correct