# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
421450 | Nicholas_Patrick | Sequence (BOI14_sequence) | C++17 | 75 ms | 716 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include <cstdio>
#include <queue>
#include <random>
using namespace std;
int singleLookup[1024];
int single(int mask){
long long ret=0, mult=1;
if(mask==1)
return 10;
for(int i=10; --i;){
if(mask>>i&1){
ret+=mult*i;
mult*=10;
}
}
if(mask&1){
mult/=10;
ret+=ret/mult*mult*9;
}
return ret;
}
long long solve(vector<int>& masks, int depth=0, bool positive=true){
if(depth>=15)
return 1;
if(masks.size()==0)
return positive;
if(masks.size()==1){
int ret=singleLookup[masks[0]];
return ret?ret:positive;
}
long long ret=102345678888889;
for(int fu=0; fu<10; fu++){
vector<int> newMasks((masks.size()-1+fu)/10+1, 0);
bool reduced=false;
for(int i=0; i<10; i++){
int u=fu+i;
bool additional=u>=10;
if(additional)
u-=10;
for(int j=0; j*10+i<masks.size(); j++){
int x=masks[j*10+i]&~(1<<u);
reduced|=x!=masks[j*10+i];
newMasks[j+additional]|=x;
}
}
while(not newMasks.empty() and newMasks.back()==0)
newMasks.pop_back();
if(not reduced and newMasks.size()==masks.size())
continue;
ret=min(ret, solve(newMasks, depth+1, fu==0)*10+fu);
}
if(ret==0)
ret=positive;
return ret;
}
int main(){
for(int i=0; i<1024; i++)
singleLookup[i]=single(i);
int k;
scanf("%d", &k);
vector<int> b(k);
for(int& i : b)
scanf("%d", &i), i=1<<i;
printf("%lld\n", solve(b));
// printf("%.3lf\n", (double)clock()/CLOCKS_PER_SEC);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |