AtCoder Grand Contest 011

Submission #1359092

Source codeソースコード

#include <iostream>
#include <cstring>
using namespace std;
int N[1000005];
char Str[500005];
int nine[1000005], sum, limit;
void Read()
{
    cin.getline(Str, 500005);
    int len = strlen(Str);
    for(int i = len - 1; i >= 0; i--)
    {
        N[++N[0]] = Str[i] - '0';
    }
    limit = N[0];
}

void Add()
{
    int t = 0, i;
    for(i = 1; i <= N[0] || i <= nine[0] || t; i++)
    {
        if(nine[i] == 0 && t == 0)
            break;
        sum -= N[i];
        N[i] = (N[i] + nine[i] + t);
        t = N[i] / 10;
        N[i] %= 10;
        sum += N[i];
    }
    N[0] = i - 1;
}
void mul()
{
      int i, t = 0;
      for (i = 1; i <= N[0] || t; i++, t /= 10)
              N[i] = (t += N[i] * 9) % 10;
      N[0] = i - 1;
      for(int i = 1; i <= N[0]; i++)
        sum += N[i];
}
void Solve()
{
    mul();
    nine[0] = 1;
    nine[1] = 9;
    for(int k = 1; k <= limit; k++)
    {
        Add();
        if(sum <= 9 * k)
        {
            cout << k << "\n";
            return;
        }
    }
}
int main()
{
    Read();
    Solve();
    return 0;
}

Submission

Task問題 E - Increasing Numbers
User nameユーザ名 alex99
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1300
Source lengthソースコード長 1133 Byte
File nameファイル名
Exec time実行時間 27 ms
Memory usageメモリ使用量 6528 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1.txt,sample2.txt,sample3.txt,sample4.txt
All 1300 / 1300 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
in1.txt AC 2 ms 4352 KB
in10.txt AC 26 ms 6400 KB
in11.txt AC 21 ms 6400 KB
in12.txt AC 21 ms 6400 KB
in13.txt AC 24 ms 6400 KB
in14.txt AC 25 ms 6400 KB
in15.txt AC 25 ms 6400 KB
in16.txt AC 25 ms 6400 KB
in17.txt AC 18 ms 6400 KB
in18.txt AC 22 ms 6400 KB
in19.txt AC 20 ms 6400 KB
in2.txt AC 22 ms 6400 KB
in20.txt AC 19 ms 6400 KB
in21.txt AC 22 ms 6400 KB
in22.txt AC 24 ms 6400 KB
in23.txt AC 22 ms 6400 KB
in24.txt AC 25 ms 6400 KB
in25.txt AC 25 ms 6400 KB
in26.txt AC 21 ms 6528 KB
in27.txt AC 16 ms 4352 KB
in28.txt AC 22 ms 6528 KB
in29.txt AC 22 ms 6400 KB
in3.txt AC 22 ms 6400 KB
in30.txt AC 22 ms 6400 KB
in31.txt AC 22 ms 6400 KB
in4.txt AC 22 ms 6400 KB
in5.txt AC 19 ms 6400 KB
in500000.txt AC 19 ms 6400 KB
in6.txt AC 23 ms 6400 KB
in7.txt AC 17 ms 4352 KB
in8.txt AC 19 ms 6400 KB
in9.txt AC 27 ms 6400 KB
sample1.txt AC 2 ms 4352 KB
sample2.txt AC 2 ms 4352 KB
sample3.txt AC 2 ms 4352 KB
sample4.txt AC 2 ms 4352 KB