Submission #2201374


Source Code Expand

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(LL i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-9;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1000000007;
const LL MAXN = 1e5 + 47;
const LL MAX = 1e5 + 47;

string s;
int n;

string n9;

string add(string& x, string& y)
{
	int sz =  max(SZ(x), SZ(y));
	string z;
	int carry = 0;
	
	RFOR(i, sz, 0)
	{
		int now = 0;
		if (i < SZ(x))
			now += (x[i] - '0');

		if (i < SZ(y))
			now += (y[i] - '0');

		if (now + carry > 9)
		{
			z.push_back('0' + (now + carry) % 10);
			carry = 1;
		}
		else
		{
			z.push_back('0' + (now + carry) % 10);
			carry = 0;
		}
	}

	if (carry)
		z.push_back('1');

	reverse(ALL(z));
	return z;
}

bool can(int k)
{
	k *= 9;
	string res;
	string K = to_string(k);
	res = add(n9, K);
	int ans = 0;
	FOR(i, 0, SZ(res))
		ans += (res[i] - '0');
	return ans <= k;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	cin >> s;
	n = SZ(s);
	n9 = s;
	string rr = n9;
	FOR(i, 0, 9)
		n9 = add(n9, s);

	//cout << n9 << endl;
	//cin >> n9;
	int L = 1, R = n, M;
	while (R - L > 1)
	{
		M = (L + R) >> 1;
		if (can(M))
			L = M;
		else
			R = M;
	}

	if (can(L))
		M = L;
	else
		M = R;

	cout << M << endl;
	cin >> n;
	return 0;
}

Submission Info

Submission Time
Task E - Increasing Numbers
User vjudge2
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2597 Byte
Status WA
Exec Time 114 ms
Memory 3044 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1300
Status
AC × 1
WA × 3
AC × 3
WA × 37
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 3 ms 384 KB
in10.txt WA 90 ms 3044 KB
in11.txt AC 87 ms 3032 KB
in12.txt WA 89 ms 3032 KB
in13.txt WA 87 ms 3032 KB
in14.txt WA 89 ms 3032 KB
in15.txt WA 89 ms 3032 KB
in16.txt WA 89 ms 3032 KB
in17.txt WA 86 ms 2860 KB
in18.txt WA 113 ms 3032 KB
in19.txt WA 106 ms 2940 KB
in2.txt WA 113 ms 3032 KB
in20.txt WA 91 ms 3032 KB
in21.txt WA 110 ms 3032 KB
in22.txt WA 110 ms 3032 KB
in23.txt WA 113 ms 3032 KB
in24.txt WA 91 ms 3032 KB
in25.txt WA 91 ms 3044 KB
in26.txt WA 106 ms 2952 KB
in27.txt WA 80 ms 2444 KB
in28.txt WA 111 ms 3044 KB
in29.txt WA 113 ms 3032 KB
in3.txt WA 114 ms 3044 KB
in30.txt WA 113 ms 3044 KB
in31.txt WA 113 ms 3032 KB
in4.txt WA 111 ms 3032 KB
in5.txt WA 90 ms 3044 KB
in500000.txt WA 90 ms 3032 KB
in6.txt WA 109 ms 3032 KB
in7.txt WA 91 ms 2564 KB
in8.txt WA 91 ms 2928 KB
in9.txt WA 92 ms 3032 KB
sample1.txt AC 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