# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1235531 | caacrugon | Broken Device (JOI17_broken_device) | C++20 | 19 ms | 1344 KiB |
#include "Annalib.h"
#include <bits/stdc++.h>
using namespace std;
void Anna(int N, long long X, int K, int P[]){
vector<int> ln(N,0);
for(int i=0;i<K;i++){
ln[P[i]]=-1;
}
vector<int> bits(N);
for(int i=0;i<N;++i){
bits[i]=(X>>i)&1LL;
}
int start=0;
for(int i=1;i<=N;i++){
if(i==N || bits[i]!=bits[start]){
int s=start,e=i-1;
int rangeType=bits[start];
int markerLen=(rangeType==1?2:1);
if(e-s+1<markerLen){
start=i;
continue;
}
int maxShifts=e-s+1-markerLen;
int shifts=0;
while(shifts<=maxShifts){
bool ok=true;
for(int j=0;j<markerLen;j++){
if(ln[s+j]==-1){
ok=false;
break;
}
}
if(ok)break;
s++;
e--;
shifts++;
}
if(shifts>maxShifts){
start=i;
continue;
}
maxShifts=e-s+1-markerLen;
shifts=0;
while(shifts<=maxShifts){
bool ok=true;
for(int j=0;j<markerLen;j++){
if(ln[e-j]==-1){
ok=false;
break;
}
}
if(ok) break;
e--;
s++;
shifts++;
}
if(shifts>maxShifts){
start=i;
continue;
}
for(int j=0;j<markerLen;j++) ln[s+j]=1;
for(int j=0;j<markerLen;j++) ln[e-j]=1;
start=i;
}
}
for(int i=0;i<N;i++){
if(ln[i]==1)Set(i, 1);
else Set(i, 0);
}
}
#include "Brunolib.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long Bruno(int N, int A[]){
vector<int> bits;
int i=0;
while(i<N){
if(A[i]!=1){
i++;
continue;
}
int len=1;
if(i+1<N && A[i+1]==1){
len=2;
}
int bit=(len==2?1:0);
int j=i+len;
while(j<N){
if(A[j]==1){
bool match=true;
for(int k=0;k<len;k++){
if(j+k>=N || A[j+k]!=1){
match=false;
break;
}
}
if(match)break;
}
++j;
}
bits.push_back(bit);
i=j+len;
}
ll x=0;
for(int idx=bits.size()-1;idx>=0;idx--){
x=(x<<1)|bits[idx];
}
return x;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |