답안 #107812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107812 2019-04-25T20:40:39 Z patrikpavic2 수열 (BOI14_sequence) C++17
100 / 100
248 ms 1520 KB
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef vector < int > vi;
typedef set < int > si;

const int N = 1e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int OFF = (1 << 18);
const int LOG = 20;
const double EPS = 1e-9;
const double PI = 3.1415926535;

int n;
vi v;

ll ans(vi msk, int devet){
    ll ret = 102345678900000LL;
    if(msk.size() == 1){
        ret = 0;
        for(int i = 1;i<10;i++){
            if(((1 << i) & msk[0])){
                ret = ret * 10LL + i;
                if(ret == i && (msk[0] & 1))
                    ret *= 10LL;
            }
        }
       if((msk[0] & 1) && ret == 0) ret = 10;

        return ret;
    }
    for(int i = 0;i < 9 + devet;i++){
        int cur = i, dos = 0, nula = 0;
        vi nw;
        for(int j = 0;j < msk.size();j++){
            int x = msk[j];
            if((x & 1) && cur == 0) nula = 1;
            if(x & (1 << cur)) x ^= (1 << cur);
            dos |= x;
            cur = (cur + 1) % 10;
            if(cur == 0 || j == msk.size() - 1) nw.PB(dos), dos = 0;
        }
      //  printf("POZIVAM NW : ");
      //  for(int x : nw) printf("%d ", x);
      //  printf("\n");
        ll nxt = ans(nw, msk.size() > 2 || i < 9) * 10LL + i;

        if(nula && nxt == 0LL) nxt = 10LL;

        ret = min(ret, nxt);
    }
     //       printf("RES: ");
    //    for(int x : msk) printf("%d ", x);
   //     printf("%lld\n", ret);
    return ret;
}

int main(){
    scanf("%d", &n);
    for(int i = 0;i < n;i++){
        int d; scanf("%d", &d);
        v.PB(1 << d);
    }
    printf("%lld\n", ans(v, 1));
    return 0;
}

Compilation message

sequence.cpp: In function 'll ans(vi, int)':
sequence.cpp:53:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0;j < msk.size();j++){
                       ~~^~~~~~~~~~~~
sequence.cpp:59:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(cur == 0 || j == msk.size() - 1) nw.PB(dos), dos = 0;
                            ~~^~~~~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
sequence.cpp:79:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int d; scanf("%d", &d);
                ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 24 ms 384 KB Output is correct
3 Correct 24 ms 384 KB Output is correct
4 Correct 25 ms 384 KB Output is correct
5 Correct 24 ms 384 KB Output is correct
6 Correct 21 ms 384 KB Output is correct
7 Correct 158 ms 1020 KB Output is correct
8 Correct 94 ms 768 KB Output is correct
9 Correct 222 ms 1272 KB Output is correct
10 Correct 195 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 111 ms 768 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 4 ms 252 KB Output is correct
11 Correct 198 ms 1392 KB Output is correct
12 Correct 198 ms 1392 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 3 ms 256 KB Output is correct
25 Correct 4 ms 316 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 25 ms 512 KB Output is correct
28 Correct 28 ms 512 KB Output is correct
29 Correct 27 ms 384 KB Output is correct
30 Correct 29 ms 384 KB Output is correct
31 Correct 20 ms 384 KB Output is correct
32 Correct 162 ms 1144 KB Output is correct
33 Correct 98 ms 892 KB Output is correct
34 Correct 201 ms 1520 KB Output is correct
35 Correct 248 ms 1400 KB Output is correct
36 Correct 183 ms 1148 KB Output is correct
37 Correct 216 ms 1272 KB Output is correct
38 Correct 143 ms 1020 KB Output is correct
39 Correct 238 ms 1392 KB Output is correct
40 Correct 221 ms 1400 KB Output is correct