답안 #400027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400027 2021-05-07T07:41:56 Z lyc 수열 (BOI14_sequence) C++14
0 / 100
70 ms 716 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;

const int mxK = 1e5+5;

int K;

ll solve(vector<int>& req, bool pad) {
    ll ret = 0;
    if (SZ(req) == 1) {
        bool zero = 0;
        FOR(i,1,9) if (req[0] & (1<<i)) {
            ret = ret*10 + i;
            if ((req[0]&1) && !zero) {
                ret = ret*10;
                zero = 1;
            }
        }
        if ((req[0]&1) && !zero && pad) {
            ret = 10;
        }
    } else {
        ret = 1e18;
        FOR(d,0,9){
            vector<int> req2;
            FOR(i,0,SZ(req)-1){
                int cur = req[i] & (~(1<<((i+d)%10)));
                if (i == 0 || (i+d)/10 != (i-1+d)/10) {
                    req2.push_back(cur);
                } else {
                    req2.back() |= cur;
                }
            }

            if (req == req2) continue; // corner case
            ll a = solve(req2,1);
            ll cur = a*10 + d;
            if (cur == 0 && (req[0]&1) && pad) cur = 10;
            ret = min(ret,cur);
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> K;

    vector<int> req;
    FOR(i,1,K){
        int A; cin >> A;
        req.push_back(1<<A);
    }

    cout << solve(req,0) << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 70 ms 716 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -