Submission #1000034
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
int main() {
long long int N;
cin >> N;
if( N ==5 ) {
vector<long long int>A( N );
for( size_t i = 0; i < N; i++ ) {
cin >> A[i];
}
long long int x = 1, ans = 0;
while( true ) {
vector<long long int>DP( 10, LLONG_MIN / 6 );
DP[0] = 0;
long long int maxx = 0;
for( size_t i = 0; i < N; i++ ) {
auto dp = DP;
for( size_t j = 0; j < 10; j++ ) {
if( dp[j] >= 0 ) {
long long int next = dp[j] + A[i];
long long int nextidx = (next / x) % 10;
DP[nextidx] = max( DP[nextidx], next % (x * 100) );
maxx = max( nextidx, maxx );
}
}
}
if( maxx == 0 ) {
break;
} else {
ans += maxx;
}
for( size_t i = 0; i < 10; i++ ) {
//cout << DP[i] << " ";
}
//cout << endl;
x *= 10;
}
cout << ans << endl;
return 0;
}
vector<long long int>A( N );
for( long long int i = 0; i < N; i++ ) {
cin >> A[i];
}
//cout << "!" << endl;
long long int x = 1LL, ans = 0LL;
for( long long int i = 0; i < 20; i++ ) {
vector<long long int>DP( 10, LLONG_MIN / 6 );
DP[0] = 0;
long long int maxx = 0;
for( long long int k = 0; k < N; k++ ) {
auto dp = DP;
DP[(A[k] / x) % 10LL] = max( A[k] % x, DP[(A[k] / x) % 10LL] );
maxx = max( (A[k] / x) % 10LL, maxx );
for( long long int j = 0; j < 10; j++ ) {
if( dp[j] >= 0LL ) {
long long int next = (dp[j] + A[k] % (x * 10LL) + x*j) % (x * 10LL);
long long int nextidx = (next / x) % 10LL;
DP[nextidx] = max( dp[nextidx], next % x );
maxx = max( nextidx, maxx );
}
}
}
ans += maxx;
//for( size_t i = 0; i < 10; i++ ) {
// cout << DP[i] << " ";
//}
//cout << endl;
//cout << maxx << endl;
x *= 10LL;
}
cout << ans << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Exact Payment |
| User | goryudyuma |
| Language | C++14 (GCC 5.4.1) |
| Score | 1500 |
| Code Size | 1846 Byte |
| Status | AC |
| Exec Time | 152 ms |
| Memory | 512 KiB |
Judge Result
| Set Name | sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 1500 / 1500 | ||||
| Status |
|
|
| 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 KiB |
| 01-02.txt | AC | 3 ms | 256 KiB |
| 01-03.txt | AC | 3 ms | 256 KiB |
| 01-04.txt | AC | 3 ms | 256 KiB |
| 01-05.txt | AC | 3 ms | 256 KiB |
| 01-06.txt | AC | 152 ms | 384 KiB |
| 01-07.txt | AC | 149 ms | 384 KiB |
| 01-08.txt | AC | 146 ms | 384 KiB |
| 01-09.txt | AC | 145 ms | 384 KiB |
| 01-10.txt | AC | 121 ms | 384 KiB |
| 01-11.txt | AC | 126 ms | 384 KiB |
| 01-12.txt | AC | 148 ms | 384 KiB |
| 01-13.txt | AC | 148 ms | 384 KiB |
| 01-14.txt | AC | 152 ms | 512 KiB |
| 01-15.txt | AC | 148 ms | 384 KiB |
| 01-16.txt | AC | 141 ms | 384 KiB |
| 01-17.txt | AC | 144 ms | 384 KiB |
| 01-18.txt | AC | 144 ms | 384 KiB |
| 01-19.txt | AC | 145 ms | 384 KiB |
| 01-20.txt | AC | 145 ms | 384 KiB |
| 01-21.txt | AC | 145 ms | 384 KiB |
| 01-22.txt | AC | 145 ms | 384 KiB |
| 01-23.txt | AC | 144 ms | 512 KiB |
| 01-24.txt | AC | 142 ms | 384 KiB |
| 01-25.txt | AC | 142 ms | 384 KiB |
| 01-26.txt | AC | 145 ms | 384 KiB |
| 01-27.txt | AC | 148 ms | 384 KiB |
| 01-28.txt | AC | 142 ms | 384 KiB |
| 01-29.txt | AC | 142 ms | 384 KiB |
| 01-30.txt | AC | 145 ms | 384 KiB |
| 01-31.txt | AC | 144 ms | 384 KiB |
| 01-32.txt | AC | 142 ms | 384 KiB |
| 01-33.txt | AC | 142 ms | 384 KiB |
| 01-34.txt | AC | 145 ms | 384 KiB |
| 01-35.txt | AC | 146 ms | 384 KiB |
| 01-36.txt | AC | 142 ms | 384 KiB |
| 01-37.txt | AC | 144 ms | 384 KiB |
| 01-38.txt | AC | 144 ms | 384 KiB |
| 01-39.txt | AC | 144 ms | 384 KiB |
| 01-40.txt | AC | 144 ms | 384 KiB |
| 01-41.txt | AC | 144 ms | 384 KiB |
| 01-42.txt | AC | 144 ms | 384 KiB |
| 01-43.txt | AC | 145 ms | 384 KiB |
| 01-44.txt | AC | 150 ms | 384 KiB |
| 01-45.txt | AC | 149 ms | 384 KiB |
| 01-46.txt | AC | 130 ms | 384 KiB |
| 01-47.txt | AC | 129 ms | 384 KiB |
| 01-48.txt | AC | 131 ms | 384 KiB |
| 01-49.txt | AC | 130 ms | 384 KiB |
| 01-50.txt | AC | 130 ms | 384 KiB |
| 01-51.txt | AC | 130 ms | 384 KiB |
| 01-52.txt | AC | 130 ms | 384 KiB |
| 01-53.txt | AC | 129 ms | 384 KiB |
| 01-54.txt | AC | 133 ms | 384 KiB |
| 01-55.txt | AC | 130 ms | 384 KiB |
| 01-56.txt | AC | 130 ms | 384 KiB |
| 01-57.txt | AC | 130 ms | 384 KiB |
| 01-58.txt | AC | 137 ms | 384 KiB |
| 01-59.txt | AC | 137 ms | 384 KiB |
| 01-60.txt | AC | 137 ms | 384 KiB |
| 01-61.txt | AC | 142 ms | 384 KiB |
| 01-62.txt | AC | 135 ms | 384 KiB |
| 01-63.txt | AC | 135 ms | 384 KiB |
| 01-64.txt | AC | 137 ms | 384 KiB |
| 01-65.txt | AC | 138 ms | 384 KiB |
| 01-66.txt | AC | 75 ms | 384 KiB |
| 01-67.txt | AC | 112 ms | 384 KiB |
| 01-68.txt | AC | 118 ms | 384 KiB |
| 01-69.txt | AC | 119 ms | 384 KiB |
| 01-70.txt | AC | 115 ms | 384 KiB |
| 01-71.txt | AC | 88 ms | 384 KiB |
| 01-72.txt | AC | 83 ms | 384 KiB |
| 01-73.txt | AC | 87 ms | 384 KiB |
| 01-74.txt | AC | 86 ms | 384 KiB |
| 01-75.txt | AC | 83 ms | 384 KiB |
| 01-76.txt | AC | 84 ms | 384 KiB |
| 01-77.txt | AC | 125 ms | 384 KiB |
| 01-78.txt | AC | 89 ms | 384 KiB |
| 01-79.txt | AC | 89 ms | 384 KiB |
| 01-80.txt | AC | 89 ms | 384 KiB |
| 01-81.txt | AC | 93 ms | 384 KiB |
| 01-82.txt | AC | 92 ms | 384 KiB |
| 01-83.txt | AC | 88 ms | 384 KiB |
| 01-84.txt | AC | 87 ms | 512 KiB |
| 01-85.txt | AC | 94 ms | 384 KiB |
| 01-86.txt | AC | 89 ms | 384 KiB |
| 01-87.txt | AC | 88 ms | 384 KiB |
| 01-88.txt | AC | 89 ms | 384 KiB |
| 01-89.txt | AC | 87 ms | 384 KiB |
| 01-90.txt | AC | 130 ms | 384 KiB |
| 01-91.txt | AC | 102 ms | 384 KiB |
| 01-92.txt | AC | 92 ms | 384 KiB |
| 01-93.txt | AC | 97 ms | 384 KiB |
| 01-94.txt | AC | 99 ms | 384 KiB |
| 01-95.txt | AC | 90 ms | 384 KiB |
| 01-96.txt | AC | 133 ms | 384 KiB |
| 01-97.txt | AC | 98 ms | 384 KiB |
| 01-98.txt | AC | 102 ms | 384 KiB |
| sample-01.txt | AC | 3 ms | 256 KiB |
| sample-02.txt | AC | 3 ms | 256 KiB |