Submission #1082614

# Submission time Handle Problem Language Result Execution time Memory
1082614 2024-08-31T18:16:13 Z Wansur Prisoner Challenge (IOI22_prison) C++17
100 / 100
12 ms 1664 KB
#include "prison.h"
#include <bits/stdc++.h>
#define ent '\n'

using namespace std;

vector<vector<int>> a;

void get(int l, int r, int i, int c){

    if(l >= r){
        return;
    }

    a[i][0] = c;
    a[i][l] = -(c + 1);
    a[i][r] = -((c ^ 1) + 1);
    if(i > 0) l++, r--;
    if(l >= r) return;

    if(0 < i && i <= 12){
        int cur = (i - 1) % 3;
        int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
        for(int x=l;x<=r;x++){
            int val = 0;
            if(x > m1) val++;
            if(x > m2) val++;
            if(val != cur){
                if(val < cur) a[i][x] = -(c + 1);
                else a[i][x] = -((c ^ 1) + 1);
            }
        }
        if(cur == 0) r = m1;
        if(cur == 1) l = m1 + 1, r = m2;
        if(cur == 2) l = m2 + 1;
    }
    else if(i > 0){
        int cur = (i - 13) % 2;
        int mid = l + r >> 1;
        for(int x=l;x<=r;x++){
            int val = (x > mid);
            if(val != cur){
                if(val < cur) a[i][x] = -(c + 1);
                else a[i][x] = -((c ^ 1) + 1);
            }
        }
        if(!cur) r = mid;
        else l = mid + 1;
    }

    a[i][l] = -(c + 1);
    a[i][r] = -((c ^ 1) + 1);
    l++, r--;
    if(l > r) return;

    if(i < 10){
        int b = ((i + 2) / 3) * 3 + 1;
        int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
        for(int x=l;x<=r;x++){
            if(x <= m1) a[i][x] = b;
            else if(x <= m2) a[i][x] = b + 1;
            else a[i][x] = b + 2;
        }
        get(l-1, r+1, b, 1 - c);
        get(l-1, r+1, b + 1, 1 - c);
        get(l-1, r+1, b + 2, 1 - c);
    }
    else{
        int b = i + (i % 2) + 1;
        if(i == 10) b = 13;
        int mid = l + r >> 1;
        for(int x=l;x<=r;x++){
            if(x <= mid) a[i][x] = b;
            else a[i][x] = b + 1;
        }
        get(l-1, r+1, b, 1 - c);
        get(l-1, r+1, b + 1, 1 - c);
    }
 }

vector<vector<int>> devise_strategy(int n) {
    int k = 20;
    for(int i=0;i<=k;i++){
        a.push_back(vector<int> (6600, 0));
    }
    get(1, 5000, 0, 0);
    for(int i=0;i<=k;i++){
        while(a[i].size() > n + 1){
            a[i].pop_back();
        }
    }
    return a;
}

Compilation message

prison.cpp: In function 'void get(int, int, int, int)':
prison.cpp:39:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |         int mid = l + r >> 1;
      |                   ~~^~~
prison.cpp:71:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |         int mid = l + r >> 1;
      |                   ~~^~~
prison.cpp: In function 'std::vector<std::vector<int> > devise_strategy(int)':
prison.cpp:88:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |         while(a[i].size() > n + 1){
      |               ~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 944 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 784 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 2 ms 1112 KB Output is correct
3 Correct 1 ms 944 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 2 ms 924 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 4 ms 1112 KB Output is correct
5 Correct 12 ms 1368 KB Output is correct
6 Correct 8 ms 1624 KB Output is correct
7 Correct 8 ms 1628 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 6 ms 1116 KB Output is correct
12 Correct 10 ms 1664 KB Output is correct