Submission #913464

# Submission time Handle Problem Language Result Execution time Memory
913464 2024-01-20T08:02:43 Z vjudge1 Mouse (info1cup19_mouse) C++17
100 / 100
55 ms 1212 KB
#include <bits/stdc++.h>

#include "grader.h"
using namespace std;
int n;

int ask(const vector<int> &q) {
        int x = query(q);
        if (x == n) {
                exit(0);
        }
        return x;
}

mt19937 rng(123123);

void solve(int n) {
        ::n = n;
        vector<int> a(n);
        iota(a.begin(), a.end(), 1);
        int cur = ask(a);
        for (int i = 0; i <= 0; i++) {
                for (int j = i + 1; j < n; j++) {
                        swap(a[i], a[j]);
                        int tmp = ask(a);
                        if (tmp > cur) {
                                cur = tmp;
                        } else {
                                swap(a[i], a[j]);
                        }
                }
        }

        vector<int> candidates;

        for (int i = 1; i < n; i++) {
                swap(a[i], a[0]);
                int x = ask(a);
                swap(a[i], a[0]);
                if (cur - x == 2) continue;
                candidates.emplace_back(i);
        }

        auto shift = [&](const vector<int> &v, bool invert = 0, bool answer = 1) {
                vector<int> b(v.size());
                for (int i = 0; i < v.size(); i++) b[i] = a[v[i]];
                for (int i = 0; i < v.size(); i++) a[v[i]] = b[(i + 1) % v.size()];
                int res = answer ? ask(a) : 0;
                if (invert) {
                        for (int i = 0; i < v.size(); i++) a[v[i]] = b[i];
                }
                return res;
        };

        while (true) {
                int diff = shift(candidates, 1) - cur;
                if (diff == 0) {
                        shift(candidates, 0, 0);
                        continue;
                }
                int last = -1;
                vector<int> good(candidates.size());
                for (int d = 1; d <= diff; d++) {
                        int low = last + 1, high = candidates.size() - 1;
                        while (low < high) {
                                int mid = low + high >> 1;
                                vector<int> tmp;
                                for (int i = 0; i <= mid; i++) tmp.emplace_back(candidates[i]);
                                if (tmp.size() != candidates.size()) {
                                        tmp.emplace_back(0);
                                        tmp.emplace_back(candidates.back());
                                }
                                if (shift(tmp, 1) - cur >= d - (mid != candidates.size() ? 1 : 0)) {
                                        high = mid;
                                } else {
                                        low = mid + 1;
                                }
                        }
                        last = high;
                        good[(high + candidates.size() - 1) % candidates.size()] = 1;
                }
                shift(candidates, 0, 0);
                vector<int> ncan;
                for (int i = 0; i < candidates.size(); i++) {
                        if (!good[i]) ncan.emplace_back(candidates[i]);
                }
                ncan.swap(candidates);
                cur += diff;
        }

        ask(a);
}

Compilation message

mouse.cpp: In lambda function:
mouse.cpp:46:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |                 for (int i = 0; i < v.size(); i++) b[i] = a[v[i]];
      |                                 ~~^~~~~~~~~~
mouse.cpp:47:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |                 for (int i = 0; i < v.size(); i++) a[v[i]] = b[(i + 1) % v.size()];
      |                                 ~~^~~~~~~~~~
mouse.cpp:50:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                         for (int i = 0; i < v.size(); i++) a[v[i]] = b[i];
      |                                         ~~^~~~~~~~~~
mouse.cpp: In function 'void solve(int)':
mouse.cpp:66:47: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |                                 int mid = low + high >> 1;
      |                                           ~~~~^~~~~~
mouse.cpp:73:69: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |                                 if (shift(tmp, 1) - cur >= d - (mid != candidates.size() ? 1 : 0)) {
      |                                                                 ~~~~^~~~~~~~~~~~~~~~~~~~
mouse.cpp:84:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |                 for (int i = 0; i < candidates.size(); i++) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct! Number of queries: 16
2 Correct 1 ms 344 KB Correct! Number of queries: 9
3 Correct 1 ms 596 KB Correct! Number of queries: 16
4 Correct 1 ms 344 KB Correct! Number of queries: 22
5 Correct 1 ms 344 KB Correct! Number of queries: 15
6 Correct 1 ms 344 KB Correct! Number of queries: 21
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct! Number of queries: 16
2 Correct 1 ms 344 KB Correct! Number of queries: 9
3 Correct 1 ms 596 KB Correct! Number of queries: 16
4 Correct 1 ms 344 KB Correct! Number of queries: 22
5 Correct 1 ms 344 KB Correct! Number of queries: 15
6 Correct 1 ms 344 KB Correct! Number of queries: 21
7 Correct 3 ms 436 KB Correct! Number of queries: 300
8 Correct 4 ms 436 KB Correct! Number of queries: 400
9 Correct 2 ms 604 KB Correct! Number of queries: 300
10 Correct 3 ms 444 KB Correct! Number of queries: 300
11 Correct 3 ms 592 KB Correct! Number of queries: 300
12 Correct 3 ms 436 KB Correct! Number of queries: 300
13 Correct 3 ms 440 KB Correct! Number of queries: 300
14 Correct 3 ms 440 KB Correct! Number of queries: 400
15 Correct 3 ms 440 KB Correct! Number of queries: 300
16 Correct 3 ms 444 KB Correct! Number of queries: 300
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Correct! Number of queries: 16
2 Correct 1 ms 344 KB Correct! Number of queries: 9
3 Correct 1 ms 596 KB Correct! Number of queries: 16
4 Correct 1 ms 344 KB Correct! Number of queries: 22
5 Correct 1 ms 344 KB Correct! Number of queries: 15
6 Correct 1 ms 344 KB Correct! Number of queries: 21
7 Correct 3 ms 436 KB Correct! Number of queries: 300
8 Correct 4 ms 436 KB Correct! Number of queries: 400
9 Correct 2 ms 604 KB Correct! Number of queries: 300
10 Correct 3 ms 444 KB Correct! Number of queries: 300
11 Correct 3 ms 592 KB Correct! Number of queries: 300
12 Correct 3 ms 436 KB Correct! Number of queries: 300
13 Correct 3 ms 440 KB Correct! Number of queries: 300
14 Correct 3 ms 440 KB Correct! Number of queries: 400
15 Correct 3 ms 440 KB Correct! Number of queries: 300
16 Correct 3 ms 444 KB Correct! Number of queries: 300
17 Correct 46 ms 1212 KB Correct! Number of queries: 2200
18 Correct 50 ms 1184 KB Correct! Number of queries: 2100
19 Correct 44 ms 696 KB Correct! Number of queries: 2100
20 Correct 54 ms 940 KB Correct! Number of queries: 2200
21 Correct 48 ms 968 KB Correct! Number of queries: 2100
22 Correct 45 ms 716 KB Correct! Number of queries: 2100
23 Correct 51 ms 968 KB Correct! Number of queries: 2100
24 Correct 51 ms 968 KB Correct! Number of queries: 2200
25 Correct 55 ms 948 KB Correct! Number of queries: 2200
26 Correct 45 ms 676 KB Correct! Number of queries: 2200