Submission #995751


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	int n;
	cin >> n;
	LL a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	LL ansnum = 0;

	vector<pair<LL,LL> > ans[n+1];
	vector<pair<LL,LL> > cur;


	for(int k = 17; k > 0; k--){
		LL r = 1;
		for(int c = 0; c < k; c++) r *= 10;
		LL p = r/10;
		for(int f = 1; f <= 9; f++){
			for(int i = 0; i <= n; i++) ans[i].clear();
			ans[0].push_back(make_pair(f*p,r-1));
			//cout << "case " << f*p << " " << r-1 << endl;
			int done = 0;
			for(int i = 0; i < n; i++){
				cur = ans[i];
				for(int l = 0; l < ans[i].size(); l++){
					if(a[i]%r >= ans[i][l].first && a[i]%r <= ans[i][l].second){
						done = 1;
						break;
					}
					LL s1 = (r+ans[i][l].first - a[i] % r)%r;
					LL e1 = (r+ans[i][l].second - a[i] % r)%r;
					cur.push_back(make_pair(s1,e1));
					//cout << s1 << " " << e1 << endl;
					if(done) break;
				}
				if(done) break;

				sort(cur.begin(), cur.end());
				/*for(int z = 0; z < cur.size(); z++){
					cout << cur[z].first << "," << cur[z].second << " ";
				}
				cout << endl;*/
				LL curs = 1e18;
				LL cure = -1;
				for(int z = 0; z < cur.size(); z++){
					if((!(cure < cur[z].first) && !(cur[z].second < curs)) || cure == -1){
						cure = max(cure,cur[z].second);
						curs = min(curs,cur[z].first);
					} else {
						ans[i+1].push_back(make_pair(curs,cure));
						curs = cur[z].first;
						cure = cur[z].second;
					}
				}
				if(cure != -1) ans[i+1].push_back(make_pair(curs,cure));

				/*for(int z = 0; z < ans[i+1].size(); z++){
					cout << ans[i+1][z].first << "," << ans[i+1][z].second << " ";
				}
				cout << endl;*/

				if(done) break;
			}
			if(done){
				ansnum ++;
				//cout << f*p << endl;
			}
		}
	}
	cout << ansnum << endl;
}

Submission Info

Submission Time
Task B - Exact Payment
User ksun48
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 1845 Byte
Status AC
Exec Time 146 ms
Memory 3712 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 32 ms 1536 KB
01-07.txt AC 45 ms 3712 KB
01-08.txt AC 42 ms 1792 KB
01-09.txt AC 42 ms 1536 KB
01-10.txt AC 84 ms 3712 KB
01-11.txt AC 71 ms 1792 KB
01-12.txt AC 45 ms 3712 KB
01-13.txt AC 45 ms 3712 KB
01-14.txt AC 32 ms 1536 KB
01-15.txt AC 45 ms 3712 KB
01-16.txt AC 52 ms 2432 KB
01-17.txt AC 50 ms 3712 KB
01-18.txt AC 50 ms 3712 KB
01-19.txt AC 42 ms 1792 KB
01-20.txt AC 42 ms 1792 KB
01-21.txt AC 50 ms 3712 KB
01-22.txt AC 50 ms 3712 KB
01-23.txt AC 50 ms 3712 KB
01-24.txt AC 47 ms 1792 KB
01-25.txt AC 47 ms 1792 KB
01-26.txt AC 50 ms 3712 KB
01-27.txt AC 42 ms 2688 KB
01-28.txt AC 34 ms 1536 KB
01-29.txt AC 47 ms 1792 KB
01-30.txt AC 49 ms 3456 KB
01-31.txt AC 50 ms 3712 KB
01-32.txt AC 47 ms 1792 KB
01-33.txt AC 47 ms 1792 KB
01-34.txt AC 50 ms 3712 KB
01-35.txt AC 44 ms 2944 KB
01-36.txt AC 47 ms 1792 KB
01-37.txt AC 38 ms 1664 KB
01-38.txt AC 50 ms 3712 KB
01-39.txt AC 50 ms 3712 KB
01-40.txt AC 50 ms 3712 KB
01-41.txt AC 48 ms 3712 KB
01-42.txt AC 51 ms 3712 KB
01-43.txt AC 50 ms 3712 KB
01-44.txt AC 35 ms 1792 KB
01-45.txt AC 38 ms 2048 KB
01-46.txt AC 32 ms 1536 KB
01-47.txt AC 32 ms 1536 KB
01-48.txt AC 32 ms 1536 KB
01-49.txt AC 32 ms 1536 KB
01-50.txt AC 32 ms 1536 KB
01-51.txt AC 30 ms 1536 KB
01-52.txt AC 32 ms 1536 KB
01-53.txt AC 32 ms 1536 KB
01-54.txt AC 31 ms 1536 KB
01-55.txt AC 32 ms 1536 KB
01-56.txt AC 32 ms 1536 KB
01-57.txt AC 32 ms 1536 KB
01-58.txt AC 32 ms 1536 KB
01-59.txt AC 32 ms 1536 KB
01-60.txt AC 33 ms 1536 KB
01-61.txt AC 32 ms 1536 KB
01-62.txt AC 32 ms 1536 KB
01-63.txt AC 32 ms 1536 KB
01-64.txt AC 32 ms 1536 KB
01-65.txt AC 31 ms 1536 KB
01-66.txt AC 146 ms 1536 KB
01-67.txt AC 88 ms 1792 KB
01-68.txt AC 67 ms 2176 KB
01-69.txt AC 76 ms 2432 KB
01-70.txt AC 75 ms 1920 KB
01-71.txt AC 118 ms 2176 KB
01-72.txt AC 127 ms 1920 KB
01-73.txt AC 119 ms 2176 KB
01-74.txt AC 127 ms 2432 KB
01-75.txt AC 135 ms 1920 KB
01-76.txt AC 133 ms 2048 KB
01-77.txt AC 71 ms 2304 KB
01-78.txt AC 120 ms 2432 KB
01-79.txt AC 110 ms 2048 KB
01-80.txt AC 114 ms 2176 KB
01-81.txt AC 106 ms 2304 KB
01-82.txt AC 109 ms 2048 KB
01-83.txt AC 131 ms 2816 KB
01-84.txt AC 129 ms 2304 KB
01-85.txt AC 122 ms 2816 KB
01-86.txt AC 128 ms 3072 KB
01-87.txt AC 132 ms 2944 KB
01-88.txt AC 131 ms 3200 KB
01-89.txt AC 129 ms 2304 KB
01-90.txt AC 59 ms 2304 KB
01-91.txt AC 94 ms 2048 KB
01-92.txt AC 125 ms 2560 KB
01-93.txt AC 117 ms 3200 KB
01-94.txt AC 108 ms 2048 KB
01-95.txt AC 124 ms 2176 KB
01-96.txt AC 52 ms 1920 KB
01-97.txt AC 95 ms 1920 KB
01-98.txt AC 107 ms 2816 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB