Submission #3413963
Source Code Expand
// Skqliao
#include <bits/stdc++.h>
#define rep(i, l, r) for (__typeof(l) i = (l), _##i##_ = (r); i < _##i##_; ++i)
#define rof(i, l, r) for (__typeof(l) i = (l) - 1, _##i##_ = (r); i >= _##i##_; --i)
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
template<typename T> bool chkMax(T &x, const T& y) {return x < y ? (x = y), 1 : 0;}
template<typename T> bool chkMin(T &x, const T& y) {return x > y ? (x = y), 1 : 0;}
typedef long long ll;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG debug("passing %d in %s\n", __LINE__, __FUNCTION__)
void open() {
freopen("number.in", "r", stdin);
freopen("number.out", "w", stdout);
}
const int MAXN = 50000 + 5;
char Str[MAXN];
int N;
bool check(int x) {
static int A[MAXN];
int len = N - 1, sum = 0;
rep(i, 0, N) {
A[i] = (Str[i] - '0') * 9;
}
A[0] += 9 * x;
for(int i = 0; i <= len; ++i) {
if(i == len && A[i] > 9) {
A[++len] = 0;
}
A[i + 1] += A[i] / 10;
A[i] %= 10;
sum += A[i];
}
return sum <= 9 * x;
}
int main() {
#ifndef ONLINE_JUDGE
open();
#endif
scanf("%s", Str);
N = strlen(Str);
std::reverse(Str, Str + N);
int l = 1, r = N;
int ans = 0;
while(l <= r) {
int m = (l + r) >> 1;
if(check(m)) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
printf("%d\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Increasing Numbers |
User |
Skqliao |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1371 Byte |
Status |
WA |
Exec Time |
1 ms |
Memory |
256 KB |
Compile Error
./Main.cpp: In function ‘void open()’:
./Main.cpp:16:34: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen("number.in", "r", stdin);
^
./Main.cpp:17:36: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen("number.out", "w", stdout);
^
./Main.cpp: In function ‘int main()’:
./Main.cpp:47:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", Str);
^
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 |