Created
August 25, 2018 13:37
-
-
Save IvanIsCoding/60aa5d68fe46012bd812564bc7b74f42 to your computer and use it in GitHub Desktop.
Japanese Olympiad in Informatics Spring Camp 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ivan Carvalho | |
| // Broken Device - JOI SC 2017 | |
| #include "Annalib.h" | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| const int MAXN = 150; | |
| static int possivel[MAXN],resposta[MAXN]; | |
| void Anna( int N, long long X, int K, int P[] ){ | |
| memset(possivel,1,sizeof(possivel)); | |
| memset(resposta,0,sizeof(resposta)); | |
| possivel[N] = 0; | |
| for(int i = 0;i<K;i++) possivel[P[i]] = 0; | |
| deque<int> digitos; | |
| while(X != 0){ | |
| digitos.push_back(X % 2); | |
| X /= 2; | |
| } | |
| for(int i = 0;i<100;i++) digitos.push_back(0); | |
| for(int i = 0;i+2<N;i+=3){ | |
| int nao_pode = (possivel[i] + 2*possivel[i+1] + 4*possivel[i+2]) ^ 7; | |
| int best_qtd = 0,mascara = 0; | |
| if(!(nao_pode & 4) && digitos[0] == 1){ | |
| best_qtd = 1; | |
| mascara = 4; | |
| } | |
| if(!(nao_pode & 2) && digitos[0] == 0){ | |
| best_qtd = 1; | |
| mascara = 2; | |
| } | |
| if(!(nao_pode & 3) && digitos[0] == 1){ | |
| best_qtd = 1; | |
| mascara = 3; | |
| } | |
| if(!(nao_pode & 6) && digitos[0] == 1 && digitos[1] == 0){ | |
| best_qtd = 2; | |
| mascara = 6; | |
| } | |
| if(!(nao_pode & 1) && digitos[0] == 0 && digitos[1] == 0){ | |
| best_qtd = 2; | |
| mascara = 1; | |
| } | |
| if(!(nao_pode & 5) && digitos[0] == 0 && digitos[1] == 1){ | |
| best_qtd = 2; | |
| mascara = 5; | |
| } | |
| if(!(nao_pode & 7) && digitos[0] == 1 && digitos[1] == 1){ | |
| best_qtd = 2; | |
| mascara = 7; | |
| } | |
| for(int j = 0;j<best_qtd;j++) digitos.pop_front(); | |
| resposta[i] = (mascara & 1) != 0; | |
| resposta[i+1] = (mascara & 2) != 0; | |
| resposta[i+2] = (mascara & 4) != 0; | |
| } | |
| for(int i = 0;i<N;i++){ | |
| Set( i, resposta[i] ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ivan Carvalho | |
| // Broken Device - JOI SC 2017 | |
| #include "Brunolib.h" | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| long long Bruno( int N, int A[] ){ | |
| vector<int> digitos; | |
| long long ans = 0; | |
| for(int i = 0;i+2<N;i+=3){ | |
| int numero = A[i] + 2*A[i+1] + 4*A[i+2]; | |
| if(numero == 0) continue; | |
| if(numero == 4 || numero == 6 || numero == 3 || numero == 7){ | |
| digitos.push_back(1); | |
| if(numero == 7) digitos.push_back(1); | |
| else if(numero == 6) digitos.push_back(0); | |
| } | |
| else{ | |
| digitos.push_back(0); | |
| if(numero == 1) digitos.push_back(0); | |
| else if(numero == 5) digitos.push_back(1); | |
| } | |
| } | |
| while(!digitos.empty() && digitos.back() == 0){ | |
| digitos.pop_back(); | |
| } | |
| for(int i = 0;i<digitos.size();i++){ | |
| if(digitos[i]) ans += (1LL << i); | |
| } | |
| return ans; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment