Submission #1003958


Source Code Expand

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;
vector<long long> p;
LL n;

long long pow_(long long a, long long n){
    if(n==0) return 1;
    long long re=pow_(a*a,n/2);
    if(n%2==1) re= re*a;
    return re;
}
vector<pair<LL,LL>> conn (vector<pair<LL,LL>> a, vector<pair<LL,LL>> b){
    REP(i,b.size()){
        a.push_back(make_pair(b[i].FI,b[i].SE));
    }
    sort(ALL(a));
    FOR(i,1,a.size()){
        if(a[i].FI<=a[i-1].SE){
            a[i].SE=max(a[i].SE,a[i-1].SE);
            a[i].FI=a[i-1].FI;
            a[i-1].FI=a[i-1].SE=0;
        }
    }
    a.erase(remove(a.begin(),a.end(),make_pair(0ll,0ll)),a.end());
    return a;
}
bool chk(LL a, vector<pair<LL,LL>> &b){
    for(auto x : b){
        if(a>=x.FI && a<=x.SE) return true;
    }
    return false;
}
int solve(int d){
    vector<pair<LL,LL>> ng;
    LL mod=pow_(10,d+1);
    ng.push_back(MP(pow_(10,d)*9,pow_(10,d+1)-1));
    REP(i,n){
        vector<pair<LL,LL>> neu;
        for(auto x: ng){
            LL l=(x.FI-p[i]%mod+mod)%mod;
            LL u=(x.SE-p[i]%mod+mod)%mod;
            if(l==0 or l>u) return 9;
            neu.push_back(make_pair(l,u));
        }
        ng=conn(ng,neu);
    }
    int re=0;
    FOR(i,0,9)if(chk(pow_(10,d)*i,ng)){
        re=9-i;
        break;
    }
    return re;
}

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

    cin >> n;
    REP(i,n){
        LL tmp;cin >> tmp;
        p.push_back(tmp);
    }

    int ans=0;
    REP(i,17) {
        ans+=solve(i);
    }
    cout << ans <<endl;

    return 0;
}

Submission Info

Submission Time
Task B - Exact Payment
User Hoi_koro
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 2496 Byte
Status AC
Exec Time 73 ms
Memory 768 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 1500 / 1500
Status
AC × 2
AC × 100
Set Name Test Cases
sample sample-01.txt, sample-02.txt
All sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt, 01-56.txt, 01-57.txt, 01-58.txt, 01-59.txt, 01-60.txt, 01-61.txt, 01-62.txt, 01-63.txt, 01-64.txt, 01-65.txt, 01-66.txt, 01-67.txt, 01-68.txt, 01-69.txt, 01-70.txt, 01-71.txt, 01-72.txt, 01-73.txt, 01-74.txt, 01-75.txt, 01-76.txt, 01-77.txt, 01-78.txt, 01-79.txt, 01-80.txt, 01-81.txt, 01-82.txt, 01-83.txt, 01-84.txt, 01-85.txt, 01-86.txt, 01-87.txt, 01-88.txt, 01-89.txt, 01-90.txt, 01-91.txt, 01-92.txt, 01-93.txt, 01-94.txt, 01-95.txt, 01-96.txt, 01-97.txt, 01-98.txt
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 256 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 13 ms 640 KB
01-07.txt AC 26 ms 640 KB
01-08.txt AC 19 ms 640 KB
01-09.txt AC 17 ms 640 KB
01-10.txt AC 41 ms 640 KB
01-11.txt AC 31 ms 640 KB
01-12.txt AC 26 ms 640 KB
01-13.txt AC 26 ms 640 KB
01-14.txt AC 13 ms 640 KB
01-15.txt AC 25 ms 640 KB
01-16.txt AC 29 ms 640 KB
01-17.txt AC 29 ms 640 KB
01-18.txt AC 29 ms 640 KB
01-19.txt AC 20 ms 640 KB
01-20.txt AC 20 ms 640 KB
01-21.txt AC 29 ms 640 KB
01-22.txt AC 29 ms 640 KB
01-23.txt AC 29 ms 640 KB
01-24.txt AC 22 ms 640 KB
01-25.txt AC 23 ms 640 KB
01-26.txt AC 29 ms 640 KB
01-27.txt AC 22 ms 640 KB
01-28.txt AC 14 ms 640 KB
01-29.txt AC 23 ms 640 KB
01-30.txt AC 28 ms 640 KB
01-31.txt AC 28 ms 640 KB
01-32.txt AC 23 ms 640 KB
01-33.txt AC 22 ms 640 KB
01-34.txt AC 29 ms 640 KB
01-35.txt AC 24 ms 640 KB
01-36.txt AC 23 ms 768 KB
01-37.txt AC 16 ms 640 KB
01-38.txt AC 30 ms 640 KB
01-39.txt AC 29 ms 640 KB
01-40.txt AC 29 ms 640 KB
01-41.txt AC 29 ms 640 KB
01-42.txt AC 29 ms 640 KB
01-43.txt AC 28 ms 640 KB
01-44.txt AC 15 ms 640 KB
01-45.txt AC 18 ms 640 KB
01-46.txt AC 13 ms 640 KB
01-47.txt AC 13 ms 640 KB
01-48.txt AC 13 ms 640 KB
01-49.txt AC 13 ms 640 KB
01-50.txt AC 13 ms 768 KB
01-51.txt AC 12 ms 640 KB
01-52.txt AC 13 ms 640 KB
01-53.txt AC 13 ms 640 KB
01-54.txt AC 12 ms 640 KB
01-55.txt AC 13 ms 640 KB
01-56.txt AC 13 ms 640 KB
01-57.txt AC 13 ms 640 KB
01-58.txt AC 13 ms 640 KB
01-59.txt AC 13 ms 640 KB
01-60.txt AC 13 ms 640 KB
01-61.txt AC 13 ms 640 KB
01-62.txt AC 13 ms 640 KB
01-63.txt AC 13 ms 640 KB
01-64.txt AC 13 ms 640 KB
01-65.txt AC 13 ms 640 KB
01-66.txt AC 58 ms 640 KB
01-67.txt AC 44 ms 640 KB
01-68.txt AC 46 ms 640 KB
01-69.txt AC 46 ms 640 KB
01-70.txt AC 41 ms 640 KB
01-71.txt AC 57 ms 640 KB
01-72.txt AC 56 ms 640 KB
01-73.txt AC 64 ms 640 KB
01-74.txt AC 66 ms 640 KB
01-75.txt AC 59 ms 640 KB
01-76.txt AC 63 ms 640 KB
01-77.txt AC 40 ms 640 KB
01-78.txt AC 69 ms 640 KB
01-79.txt AC 50 ms 640 KB
01-80.txt AC 65 ms 640 KB
01-81.txt AC 56 ms 640 KB
01-82.txt AC 55 ms 640 KB
01-83.txt AC 70 ms 640 KB
01-84.txt AC 65 ms 640 KB
01-85.txt AC 68 ms 640 KB
01-86.txt AC 73 ms 640 KB
01-87.txt AC 69 ms 640 KB
01-88.txt AC 72 ms 640 KB
01-89.txt AC 63 ms 640 KB
01-90.txt AC 33 ms 640 KB
01-91.txt AC 44 ms 640 KB
01-92.txt AC 64 ms 640 KB
01-93.txt AC 67 ms 640 KB
01-94.txt AC 51 ms 640 KB
01-95.txt AC 59 ms 640 KB
01-96.txt AC 28 ms 640 KB
01-97.txt AC 45 ms 640 KB
01-98.txt AC 57 ms 640 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB