Submission #1686388
Source Code Expand
#include <bits/stdc++.h> #define For(i, j, k) for(int i = j; i <= k; i++) #define Forr(i, j, k) for(int i = j; i >= k; i--) using namespace std; const int N = 500010; char S[N]; int n; set<int> pos; int main(){ scanf("%s", S + 1); n = strlen(S + 1); int ans = 1; For(i, 1, n - 1) if(S[i] > S[i + 1]) pos.insert(i); For(i, 1, n - 1) if(S[i] >= S[i + 1] && pos.size() && S[*pos.begin()] == S[i]){ if(S[i] > S[i + 1]) pos.erase(i); ++ans; S[n]++; int l = i, bound = l; S[l] = '0'; Forr(j, n, l + 1){ if(S[j] > '9'){ S[j] = '0'; S[j - 1]++; } else{ bound = j - 1; break; } } For(j, bound, n - 1){ if(S[j] <= S[j + 1] && pos.count(j)) pos.erase(j); else if(S[j] > S[j + 1] && !pos.count(j)) pos.insert(j); } // printf("%s\n", S + 1); i = l - (S[l] > '0'); } else S[i] = '0'; printf("%d\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Increasing Numbers |
User | dy0607 |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 943 Byte |
Status | AC |
Exec Time | 156 ms |
Memory | 12928 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:16:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s", S + 1); ^
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 | 512 KB |
in10.txt | AC | 12 ms | 768 KB |
in11.txt | AC | 5 ms | 768 KB |
in12.txt | AC | 8 ms | 768 KB |
in13.txt | AC | 12 ms | 768 KB |
in14.txt | AC | 13 ms | 768 KB |
in15.txt | AC | 15 ms | 768 KB |
in16.txt | AC | 20 ms | 768 KB |
in17.txt | AC | 5 ms | 640 KB |
in18.txt | AC | 125 ms | 11392 KB |
in19.txt | AC | 64 ms | 6528 KB |
in2.txt | AC | 138 ms | 11264 KB |
in20.txt | AC | 5 ms | 768 KB |
in21.txt | AC | 128 ms | 11264 KB |
in22.txt | AC | 133 ms | 11264 KB |
in23.txt | AC | 139 ms | 11264 KB |
in24.txt | AC | 12 ms | 768 KB |
in25.txt | AC | 12 ms | 768 KB |
in26.txt | AC | 130 ms | 10880 KB |
in27.txt | AC | 85 ms | 8064 KB |
in28.txt | AC | 133 ms | 11264 KB |
in29.txt | AC | 133 ms | 11264 KB |
in3.txt | AC | 152 ms | 11264 KB |
in30.txt | AC | 149 ms | 11264 KB |
in31.txt | AC | 148 ms | 11264 KB |
in4.txt | AC | 130 ms | 11264 KB |
in5.txt | AC | 5 ms | 768 KB |
in500000.txt | AC | 5 ms | 768 KB |
in6.txt | AC | 156 ms | 12928 KB |
in7.txt | AC | 70 ms | 6400 KB |
in8.txt | AC | 5 ms | 768 KB |
in9.txt | AC | 12 ms | 768 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |
sample4.txt | AC | 1 ms | 256 KB |