# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
474950 | 2021-09-20T10:24:13 Z | cs71107 | 수열 (BOI14_sequence) | C++14 | 60 ms | 1364 KB |
#include <bits/stdc++.h> #define f first #define s second #define MOD 1000000007 #define PMOD 998244353 #define pb(x) push_back(x) using namespace std; typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> plii; typedef pair<int, pii> piii; const int INF = 1e9+10; const ll LINF = 1LL*INF*INF; const int MAXN = 2e5+10; const int MAXM = 5e3+10; priority_queue<int> pq; vector<vector<int> > graph; queue<int> que; int A[MAXN]; int vv[20][MAXN]; ll solve(int t,int n){ ll res = LINF; if(n==1){ int curv = vv[t][0]; if(curv&1){ if(curv==1){ res = 10; } else { res = 0; for(int i=1;i<10;i++){ if((1<<i)&curv){ if(!res){ res = (i*10); } else { res = 10LL*res+i; } } } } } else { res = 0; for(int i=1;i<10;i++){ if((1<<i)&curv){ res = 10LL*res+i; } } } } else if(n==2){ res = LINF; int a,b; ll curres = LINF; for(int i=0;i<9;i++){ a = vv[t][0]&(1023^(1<<i)); b = vv[t][1]&(1023^(1<<(i+1))); vv[t+1][0] = a|b; curres = solve(t+1,1); if(curres){ res = min(res,curres*10LL+i); } else if((!i)&&(vv[t][0]&1)){ res = min(res,10LL); } else { res = min(res,(ll)i); } } if((vv[t][0]&512)||(vv[t][1]&1)){ a = vv[t][0]&511; b = vv[t][1]&1022; vv[t+1][0] = a; vv[t+1][1] = b; curres = solve(t+1,2); res = min(res,curres*10LL+9); } } else { int cnt = 0; int idx = 0; int cur; ll curans = LINF; for(int tt=0;tt<10;tt++){ cnt = 0; idx = tt; vv[t+1][0] = 0; for(int i=0;i<n;i++){ cur = vv[t][i]&(1023^(1<<idx)); vv[t+1][cnt]|=cur; idx++; if(idx==10){ idx = 0; cnt++; vv[t+1][cnt] = 0; } } if(idx){ curans = solve(t+1,cnt+1); } else { curans = solve(t+1,cnt); } //cout<<t<<" "<<curans<<"\n"; if(curans){ res = min(res,curans*10LL+tt); } else if((!tt)&&(vv[t][0]&1)){ res = min(res,10LL); } else { res = min(res,(ll)tt); } } } return res; } int main() { int n,m,k,a,b,x,y,q; int sum = 0; int cnt = 0; int mx = 0; int mn = INF; int cur = 0, idx = -1; int tc; ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for(int i=0;i<n;i++) { cin>>A[i]; } for(int i=0;i<n;i++){ vv[0][i] = (1<<A[i]); } ll res = solve(0,n); cout<<res<<"\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 2 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 320 KB | Output is correct |
18 | Correct | 1 ms | 456 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 6 ms | 456 KB | Output is correct |
3 | Correct | 6 ms | 332 KB | Output is correct |
4 | Correct | 6 ms | 332 KB | Output is correct |
5 | Correct | 4 ms | 332 KB | Output is correct |
6 | Correct | 3 ms | 332 KB | Output is correct |
7 | Correct | 28 ms | 844 KB | Output is correct |
8 | Correct | 24 ms | 720 KB | Output is correct |
9 | Correct | 40 ms | 1156 KB | Output is correct |
10 | Correct | 36 ms | 1152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 27 ms | 680 KB | Output is correct |
6 | Correct | 0 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 0 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 316 KB | Output is correct |
11 | Correct | 37 ms | 1356 KB | Output is correct |
12 | Correct | 50 ms | 1364 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 324 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 6 ms | 476 KB | Output is correct |
28 | Correct | 6 ms | 460 KB | Output is correct |
29 | Correct | 5 ms | 472 KB | Output is correct |
30 | Correct | 4 ms | 460 KB | Output is correct |
31 | Correct | 3 ms | 332 KB | Output is correct |
32 | Correct | 26 ms | 972 KB | Output is correct |
33 | Correct | 23 ms | 828 KB | Output is correct |
34 | Correct | 36 ms | 1356 KB | Output is correct |
35 | Correct | 37 ms | 1344 KB | Output is correct |
36 | Correct | 43 ms | 972 KB | Output is correct |
37 | Correct | 59 ms | 1352 KB | Output is correct |
38 | Correct | 35 ms | 844 KB | Output is correct |
39 | Correct | 60 ms | 1292 KB | Output is correct |
40 | Correct | 58 ms | 1356 KB | Output is correct |