Submission #1262754

#TimeUsernameProblemLanguageResultExecution timeMemory
1262754niepamietamhaslaBroken Device (JOI17_broken_device)C++20
100 / 100
31 ms1580 KiB
#include "Annalib.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; void Anna(int n, ll x, int k, int* S){ vector<int> czy(n, 0); for(int i = 0; i < k; ++i){ czy[S[i]] = 1; } vector<int> P; for(int i = 0; i < n; ++i){ P.push_back(i); } mt19937 rng(5); shuffle (P.begin(), P.end(), rng); int it = 0; while(x > 0){ int reszta = x % 3; ll C = P[it]; ll N = P[it+1]; if(czy[C] == 0 and czy[N] == 0){ if(reszta == 2){ Set(C, 1); Set(N, 1); it+=2; } else if(reszta == 1){ Set(C, 1); Set(N, 0); it+=2; } else{ Set(C, 0); Set(N, 1); it+=2; } x /= 3; } else if(czy[C] == 0 and reszta == 1){ Set(C, 1); Set(N, 0); it += 2; x /= 3; } else if(czy[N] == 0 and reszta == 0){ Set(C, 0); Set(N, 1); it += 2; x /= 3; } else{ Set(C, 0); Set(N, 0); it += 2; } } while(it < n) { ll C = P[it]; Set(C, 0); ++it; } return; }
#include "Brunolib.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll Bruno(int n, int* A){ vector<int> P; for(int i = 0; i < n; ++i){ P.push_back(i); } mt19937 rng(5); shuffle (P.begin(), P.end(), rng); ll pot = 1; ll S = 0; for(int i = 0; i < n; i += 2){ int x = P[i]; int y = P[i+1]; if(A[x] == 0 and A[y] == 0){ continue; } else if(A[x] == 1 and A[y] == 1){ S += 2 * pot; pot *= 3; } else if(A[x] == 1){ S += pot; pot *= 3; } else{ pot *= 3; } } return S; }
#Verdict Execution timeMemoryGrader output
Fetching results...