Submission #107813

# Submission time Handle Problem Language Result Execution time Memory
107813 2019-04-25T20:41:47 Z patrikpavic2 Sequence (BOI14_sequence) C++17
25 / 100
240 ms 1272 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, bool devet,int dubina){
    ll ret = 123456789000000LL;

    if(!msk.size()) return 0;
    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;
        /**
        for(int x : msk){
            printf("MSK{%d} :", dubina);
            printf("{");
            for(int i = 0;i < 10;i++) if(x & (1 << i)) printf("%d ", i);
            printf("} ");
        }
        printf("   RET %lld\n", ret);
        **/
        return ret;
    }
    for(int i = 0;i < 9 + devet;i++){
        int cur = i, dos = 0, nula = 0;
        vi nw;
        for(int x : msk){
            if(x & 1) nula = 1;
            if(x & (1 << cur)) x ^= (1 << cur);
            dos |= x;
            if(cur == 9) nw.PB(dos), dos = 0;
            cur = (cur + 1) % 10;
        }
        if(dos) nw.PB(dos);
        ll nxt = ans(nw, nw.size() > 2 || i < 9, dubina + 1) * 10LL + i;
        if(nula && !nxt) nxt = 10LL;
        ret = min(ret, nxt);
    }
    /**
    printf("DUBINA %d => %lld\n", dubina, ret);

    printf("MSK{%d} :", dubina);
    for(int x : msk){
        printf("{");
        for(int i = 0;i < 10;i++) if(x & (1 << i)) printf("%d ", i);
        printf("} ");
    }
    printf("   RET %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));
    }
    ll fin = ans(v, 1, 0);
    if(fin == 0) fin = 10LL;
    printf("%lld\n", fin);
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
sequence.cpp:92:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int d; scanf("%d", &d);
                ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Incorrect 2 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 44 ms 384 KB Output is correct
3 Correct 24 ms 384 KB Output is correct
4 Correct 13 ms 384 KB Output is correct
5 Correct 14 ms 384 KB Output is correct
6 Correct 22 ms 384 KB Output is correct
7 Correct 136 ms 952 KB Output is correct
8 Correct 98 ms 768 KB Output is correct
9 Correct 195 ms 1272 KB Output is correct
10 Correct 240 ms 1220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 93 ms 768 KB Output is correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -