Submission #1172940

#TimeUsernameProblemLanguageResultExecution timeMemory
1172940SpyrosAlivPrisoner Challenge (IOI22_prison)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; int len(int x) { int sz = 0; while (x > 0) { x /= 10; sz++; } return sz; } int find_digit(int a, int d) { string s = ""; while (a > 0) { s += ((a % 10) + '0'); a /= 10; } reverse(s.begin(), s.end()); for (int i = 0; i < 4; i++) s += '0'; return s[d - 1] - '0'; } string convert(int a) { string tr = ""; while (a > 0) { tr += ((a % 3) + '0'); a /= 3; } while (tr.size() < 7) tr += '0'; reverse(tr.begin(), tr.end()); return tr; } vector<vector<int>> devise_strategy(int n) { vector<vector<int>> s(28, vector<int>(n+1, -1)); s[0][0] = 0; // the first prisoner will write the amount of digits A has // the second prisoner will compare this with the amount of digits B has // if they have same no. digits: /* the current prisoner will write the current digit of A on the board (form: pd, where p is the position of the digit and d is its value) the next prisoner will compare with the respective digit of B if they are equal, he will write which digit of A must be inspected next (added + 4) (so it doesnt conflict with the number written by the first pr.) max X: 49 */ /* Idea: We can convert the number to base 3 and compare them the prisoners will write on the board in the form vd, meaning that digit d has value of v even digits -> it corresponds to A odd digits -> it corresponds to B */ for (int i = 1; i <= n; i++) { string t = convert(i); // read A and write down the first digit of its trinary rep s[0][i] = (t[0] - '0') * 10 + 1; } for (int read = 1; read <= 27; read++) { int val = read / 10; int idx = read % 10 - 1; // which bit needs to be compared with val if (idx >= 8) continue; if (idx % 2 == 0) { // this corresponds to A s[read][0] = 1; for (int poss = 1; poss <= n; poss++) { string t = convert(poss); int k = t[idx] - '0'; if (k < val) { s[read][poss] = -2; } else if (k > val) { s[read][poss] = -1; } else { if (idx + 2 >= 8) s[read][poss] = -1; else s[read][poss] = (t[idx + 1] - '0') * 10 + idx + 2; } } } else { // this corresponds to B s[read][0] = 0; for (int poss = 1; poss <= n; poss++) { string t = convert(poss); int k = t[idx] - '0'; if (k > val) { s[read][poss] = -2; } else if (k < val) { s[read][poss] = -1; } else { if (idx + 2 >= 8) s[read][poss] = -1; else s[read][poss] = (t[idx + 1] - '0') * 10 + idx + 2; } } } } return s; /* for (int i = 1; i <= 4; i++) { // read i on the board s[i][0] = 1; // see B for (int j = 1; j <= n; j++) { if (len(j) < i) { s[i][j] = -2; } else if (len(j) > i) { s[i][j] = -1; } else s[i][j] = 1 + 4; // we need to see the first digit of A; add 1 so it doesnt conflict with the no. of digits of A } } for (int i = 5; i <= 8; i++) { // we need to see this digit of A next s[i][0] = 0; int need = i - 4; for (int j = 1; j <= n; j++) { s[i][j] = need * 10 + find_digit(j, need); } } for (int i = 10; i <= 49; i++) { // we know that the i[0] digit of A is i[1] s[i][0] = 1; int v = i % 10; int d = i / 10; for (int j = 1; j <= n; j++) { int rep = find_digit(j, d); if (rep < v) { s[i][j] = -2; } else if (rep > v) { s[i][j] = -1; } else { s[i][j] = d + 1 + 4; // we must see the next digit } } }*/ return s; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...