Submission #1333173
Source Code Expand
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define maxn 500100 #define lson root << 1 #define rson root << 1 | 1 #define lent (t[root].r - t[root].l + 1) #define lenl (t[lson].r - t[lson].l + 1) #define lenr (t[rson].r - t[rson].l + 1) #define N 1111 #define eps 1e-6 #define pi acos(-1.0) #define e exp(1.0) using namespace std; const int mod = 1e9 + 7; typedef long long ll; typedef unsigned long long ull; char s[maxn]; int a[maxn]; int len; bool check(int x) { int sum = x * 9, cnt = 0; for (int i = 0; i < len; i++) { sum += a[i]; cnt += sum % 10; sum /= 10; } while (sum > 0) { cnt += sum % 10; sum /= 10; } return cnt <= x * 9; } int main() { while (~scanf("%s", s)) { memset(a, 0, sizeof(a)); len = strlen(s); reverse(s, s + len); for (int i = 0; i < len; i++) a[i] = (s[i] - '0') * 9; for (int i = 0; i < len; i++) { a[i + 1] += a[i] / 10; a[i] %= 10; } if (a[len]) len++; int l = 0, r = len * 2, ans = -1; while (l < r) { int mid = l + r >> 1; if (check(mid)) { ans = mid; r = mid; } else l = mid + 1; } printf("%d\n", ans); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Increasing Numbers |
User | vjudge1 |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 1402 Byte |
Status | AC |
Exec Time | 35 ms |
Memory | 2688 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt, sample4.txt |
All | sample1.txt, sample2.txt, sample3.txt, sample4.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in4.txt, in5.txt, in500000.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 2 ms | 2176 KB |
in10.txt | AC | 34 ms | 2688 KB |
in11.txt | AC | 35 ms | 2688 KB |
in12.txt | AC | 34 ms | 2688 KB |
in13.txt | AC | 34 ms | 2688 KB |
in14.txt | AC | 34 ms | 2688 KB |
in15.txt | AC | 34 ms | 2688 KB |
in16.txt | AC | 34 ms | 2688 KB |
in17.txt | AC | 33 ms | 2688 KB |
in18.txt | AC | 34 ms | 2688 KB |
in19.txt | AC | 34 ms | 2688 KB |
in2.txt | AC | 34 ms | 2688 KB |
in20.txt | AC | 34 ms | 2688 KB |
in21.txt | AC | 34 ms | 2688 KB |
in22.txt | AC | 34 ms | 2688 KB |
in23.txt | AC | 34 ms | 2688 KB |
in24.txt | AC | 34 ms | 2688 KB |
in25.txt | AC | 33 ms | 2688 KB |
in26.txt | AC | 33 ms | 2688 KB |
in27.txt | AC | 25 ms | 2560 KB |
in28.txt | AC | 33 ms | 2688 KB |
in29.txt | AC | 34 ms | 2688 KB |
in3.txt | AC | 34 ms | 2688 KB |
in30.txt | AC | 34 ms | 2688 KB |
in31.txt | AC | 34 ms | 2688 KB |
in4.txt | AC | 32 ms | 2688 KB |
in5.txt | AC | 34 ms | 2688 KB |
in500000.txt | AC | 35 ms | 2688 KB |
in6.txt | AC | 34 ms | 2688 KB |
in7.txt | AC | 28 ms | 2560 KB |
in8.txt | AC | 34 ms | 2688 KB |
in9.txt | AC | 32 ms | 2688 KB |
sample1.txt | AC | 2 ms | 2176 KB |
sample2.txt | AC | 2 ms | 2176 KB |
sample3.txt | AC | 2 ms | 2176 KB |
sample4.txt | AC | 2 ms | 2176 KB |