# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990649 | MarwenElarbi | Broken Device (JOI17_broken_device) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define MAX_K 40
#define MAX_N 150
static int Q, N, K, A[MAX_N], P[MAX_K];
static long long X;
static int min_wa = MAX_K + 1;
void WrongAnswer( int e ){
fprintf( stderr, "Wrong Answer [%d]\n", e );
exit( 0 );
}
void Set( int pos, int bit ){
if( !( 0 <= pos && pos < N ) ){
WrongAnswer( 1 );
}
if( A[pos] != -1 ){
WrongAnswer( 2 );
}
if( !( bit == 0 || bit == 1 ) ){
WrongAnswer( 3 );
}
A[pos] = bit;
}
void Anna( int N, long long X, int K, int P[] ){
int tab[N];
memset(tab,0,sizeof tab);
for (int i = 0; i < K; ++i)
{
tab[P[i]]=-1;
}
int convert[65];
for (int i = 0; i < 64; ++i)
{
convert[i]=((1<<i)&X)>0;
//cout <<convert[i]<<" ";
}//cout <<endl;
int lst=0;
for (int i = 0; i < N-1; ++i)
{
if(tab[i]!=-1&&tab[i+1]!=-1){
tab[i]=(convert[lst]==1);
tab[i+1]=1;
lst++;
i+=2;
}
}
for (int i = 0; i < N; ++i)
{
//cout <<tab[i]<<" ";
if(tab[i]==1) Set(i,1);
else Set(i,0);
}//cout <<endl;
}
long long Bruno( int N, int A[] ){
int lst=0;
long long x=0;
for (int i = 0; i < N-2; ++i)
{
if(A[i+1]==1&&A[i+2]!=1){
if(A[i]==1) x+=(1<<lst);
lst++;
}
}
if(A[N-1]==1&&A[N-2]==1) x+=(1<<lst);
//cout <<x<<endl;
return x;
}
/*int main( int argc, char** argv ){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int i, query_cnt;
long long ans;
scanf( "%d", &Q );
for( query_cnt = 0; query_cnt < Q; query_cnt++ ){
scanf( "%d %lld %d", &N, &X, &K );
for( i = 0; i < K; i++ ){
scanf( "%d", &P[i] );
}
for( i = 0; i < N; i++ ){
A[i] = -1;
}
Anna( N, X, K, P );
for( i = 0; i < N; i++ ){
if( A[i] == -1 ){
WrongAnswer( 4 );
}
}
for( i = 0; i < K; i++ ){
A[ P[i] ] = 0;
}
ans = Bruno( N, A );
if( ans != X ){
if( K < min_wa ){
min_wa = K;
}
}
}
if( min_wa == 1 ){
if( K < min_wa ){
min_wa = K;
}
}
fprintf( stderr, "Accepted\n" );
fprintf( stderr, "L* = %d\n", min_wa - 1 );
return 0;
}*/