Submission #1291051
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() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock(); #endif 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); } #ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time); #endif return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Increasing Numbers |
User | vjudge1 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1646 Byte |
Status | WA |
Exec Time | 1 ms |
Memory | 256 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:39:34: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result] freopen("in.txt", "r", stdin); ^ ./Main.cpp:40:36: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result] freopen("out.txt", "w", stdout); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | WA | 1 ms | 256 KB |
in10.txt | WA | 1 ms | 256 KB |
in11.txt | WA | 1 ms | 256 KB |
in12.txt | WA | 1 ms | 256 KB |
in13.txt | WA | 1 ms | 256 KB |
in14.txt | WA | 1 ms | 256 KB |
in15.txt | WA | 1 ms | 256 KB |
in16.txt | WA | 1 ms | 256 KB |
in17.txt | WA | 1 ms | 256 KB |
in18.txt | WA | 1 ms | 256 KB |
in19.txt | WA | 1 ms | 256 KB |
in2.txt | WA | 1 ms | 256 KB |
in20.txt | WA | 1 ms | 256 KB |
in21.txt | WA | 1 ms | 256 KB |
in22.txt | WA | 1 ms | 256 KB |
in23.txt | WA | 1 ms | 256 KB |
in24.txt | WA | 1 ms | 256 KB |
in25.txt | WA | 1 ms | 256 KB |
in26.txt | WA | 1 ms | 256 KB |
in27.txt | WA | 1 ms | 256 KB |
in28.txt | WA | 1 ms | 256 KB |
in29.txt | WA | 1 ms | 256 KB |
in3.txt | WA | 1 ms | 256 KB |
in30.txt | WA | 1 ms | 256 KB |
in31.txt | WA | 1 ms | 256 KB |
in4.txt | WA | 1 ms | 256 KB |
in5.txt | WA | 1 ms | 256 KB |
in500000.txt | WA | 1 ms | 256 KB |
in6.txt | WA | 1 ms | 256 KB |
in7.txt | WA | 1 ms | 256 KB |
in8.txt | WA | 1 ms | 256 KB |
in9.txt | WA | 1 ms | 256 KB |
sample1.txt | WA | 1 ms | 256 KB |
sample2.txt | WA | 1 ms | 256 KB |
sample3.txt | WA | 1 ms | 256 KB |
sample4.txt | WA | 1 ms | 256 KB |