Submission #1126012

#TimeUsernameProblemLanguageResultExecution timeMemory
1126012mariaclaraBroken Device (JOI17_broken_device)C++20
100 / 100
30 ms1488 KiB
#include "Annalib.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mk make_pair #define pb push_back #define fr first #define sc second void Anna( int N, ll X, int K, int P[] ){ vector<int> B(N, 1); for(int i = 0; i < K; i++) B[P[i]] = 0; vector<pair<string,string>> corr = { {"111", "11"}, {"110", "10"}, {"101", "01"}, {"001", "00"}, {"010", "0"}, {"100", "1"}, {"011", "1"} }; string bit; while(X != 0) { bit += char(X%2 + '0'); X /= 2; } for(int i = 0, j = 0; i < N/3; i++) { bool send = 0; for(int aux = 0; aux < 7 and j < sz(bit); aux++) { int b1 = (int)(corr[aux].fr[0] - '0') and B[3*i]; int b2 = (int)(corr[aux].fr[1] - '0') and B[3*i + 1]; int b3 = (int)(corr[aux].fr[2] - '0') and B[3*i + 2]; string seq; seq += char(b1 + '0'); seq += char(b2 + '0'); seq += char(b3 + '0'); if(seq != corr[aux].fr) continue; if(corr[aux].sc[0] != bit[j]) continue; if(sz(corr[aux].sc) == 1) { Set(3*i, corr[aux].fr[0] - '0'); Set(3*i + 1, corr[aux].fr[1] - '0'); Set(3*i + 2, corr[aux].fr[2] - '0'); send = 1; j++; break; } if(corr[aux].sc[1] == '0' and (j+1 == sz(bit) or bit[j+1] == '0')) { Set(3*i, corr[aux].fr[0] - '0'); Set(3*i + 1, corr[aux].fr[1] - '0'); Set(3*i + 2, corr[aux].fr[2] - '0'); send = 1; j += 2; break; } if(corr[aux].sc[1] == '1' and j+1 != sz(bit) and bit[j+1] == '1') { Set(3*i, corr[aux].fr[0] - '0'); Set(3*i + 1, corr[aux].fr[1] - '0'); Set(3*i + 2, corr[aux].fr[2] - '0'); send = 1; j += 2; break; } } if(!send) { Set(3*i, 0); Set(3*i + 1, 0); Set(3*i + 2, 0); } } }
#include "Brunolib.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mk make_pair #define pb push_back #define fr first #define sc second ll Bruno( int N, int A[] ){ vector<pair<string,string>> corr = { {"111", "11"}, {"110", "10"}, {"101", "01"}, {"001", "00"}, {"010", "0"}, {"100", "1"}, {"011", "1"} }; string bit; for(int i = 0; i < N/3; i++) { string seq; seq += A[3*i] + '0'; seq += A[3*i + 1] + '0'; seq += A[3*i + 2] + '0'; for(auto aux = 0; aux < 7; aux++) if(corr[aux].fr == seq) bit += corr[aux].sc; } ll X = 0; for(int i = 0; i < sz(bit); i++) X += ((ll)1 << i) * (int)(bit[i] - '0'); return X; }
#Verdict Execution timeMemoryGrader output
Fetching results...