QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560252#6407. Classical A+B Problemucup-team4893#AC ✓6ms3704kbC++141.7kb2024-09-12 14:35:582024-09-12 14:35:58

Judging History

This is the latest submission verdict.

  • [2024-09-12 14:35:58]
  • Judged
  • Verdict: AC
  • Time: 6ms
  • Memory: 3704kb
  • [2024-09-12 14:35:58]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

string n; 

int digitsum(string n) {
	if(n[0] != '0') return -1;
	reverse(n.begin(), n.end());
	n.pop_back();
	int cnt = 0, sum = 0, q = 0;
	for(char ch : n) {
		if(q && sum == 1) sum += 10000000; 
		if(ch != '0') {
			cnt++, sum += ch - 48;
			if(cnt == 2 && !q) sum %= 100;
			q = 1;
		}
		else q = 0;
		if(cnt > 2) return -1;
	}
	return sum;
}

void work() {
	cin >> n;
	reverse(n.begin(), n.end());
	n += '0';
	int p = 0;
	for(char &ch : n) {
		ch -= 48;
		ch = ch * 9 + p;
		p = ch / 10;
		ch %= 10;
		ch += 48;
	}
	if(n.back() == '0') n.erase(n.size() - 1, 1);
	//cout << n << '\n';
	for(int i = 1; i <= 18; i++) {
		n += '0';
		int p = 1;
		for(char &ch : n) {
			ch -= 48;
			ch = ch + p;
			p = ch / 10;
			ch %= 10;
			ch += 48;
		}
		if(n.back() == '0') n.erase(n.size() - 1, 1);
		if(i == 1) continue;
		int ds = digitsum(n);
		//cout << n << ' ' << i << ' ' << ds << endl;
		if(ds % 100 == i) {
			int i1 = 0, i2 = 0;
			while(n[i1] == 48) i1++;
			i2 = i1 + 1;
			while(n[i2] == 48) i2++;
			int flg = 0;
			if(n[i1] - 48 == i) flg = 1, n[i1]--, i2 = i1;
			for(int j = 0; j < i1; j++) cout << n[i1]; cout << ' ';
			n[i1] = '1';
			for(int j = 0; j < i2; j++) cout << n[i2]; cout << '\n';
		}
		else if(ds % 100 == i % 10 + 1 && ds > 100) {
			//cout << n << '\n';
			int i1 = n.size() - 1;
			while(n[i1] == 48) i1--;
			i1--;
			for(int j = 0; j < i1; j++) cout << 9; cout << ' ';
			i -= 9;
			for(int j = 0; j < i1; j++) cout << i; cout << '\n';
		}
		else continue;
		break;
	}
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int _; cin >> _; while(_--) work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3612kb

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

1 1
9 777
999 333
222 88888
111111 2222222
2 9999999999999999999999999999

result:

ok ok (6 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

100
854
77777777781111111111111111110
44444450
11111111111111333
2310
5
333333333333333333333343332
888999
10
11113333
335
77779
88888888888888888888889111111111111111111110
55555555555555777777
72222222222222222222221
666
5777
1111555555
444444444544444444443
88888888888891111111111110
673332
97
77...

output:

77 777
3333333333333333333 77777777777777777777777777777
6 44444444
222 11111111111111111
88 2222
4 1
9999 333333333333333333333333333
111 888888
9 1
2222 11111111
2 333
2 77777
222222222222222222222 88888888888888888888888888888888888888888888
222222 55555555555555555555
5555555555555555555555 6666...

result:

ok ok (100 test cases)

Test #3:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

1000
999999
1199
888891
33333333344
6
55555633333333333333333333333333332
444999
333333333333333343333332
10000000055554
76666666666666666666666665
2310
55555633332
166666666666666
111111111111111888888888888888888
891
8888889333333333332
7
555555556666666666
22266666666666
7778554
667
5555555556222...

output:

888888 111111
88 1111
3 888888
11 33333333333
5 1
77777777777777777777777777777 55555555555555555555555555555555555
555 444444
9999999 333333333333333333333333
55555 9999999999999
9999999999999999999999999 66666666666666666666666666
88 2222
77777 55555555555
55555555555555 111111111111111
7777777777...

result:

ok ok (1000 test cases)

Test #4:

score: 0
Accepted
time: 6ms
memory: 3568kb

input:

10000
321
7777777854
2
3666
55566666666
6666666699
49
2888888
10000888888888888888887
5654
99
6555554
10
5
222222255555
2777
8
777779
3333333333377777777
77
667666665
110
9
7777777777777777788888888888
8
6
444444532
555556555555555555554
10000099998
610
1000000000000000055554
34444
5555666666
188888...

output:

99 222
77 7777777777
1 1
333 3333
11111111 55555555555
33 6666666666
5 44
666666 2222222
888888888888888888 9999999999999999999999
99 5555
88 11
999999 5555555
9 1
4 1
33333 222222222222
555 2222
7 1
2 777777
44444444 3333333333333333333
66 11
999999 666666666
99 11
8 1
11111111111 77777777777777777...

result:

ok ok (10000 test cases)

Test #5:

score: 0
Accepted
time: 5ms
memory: 3632kb

input:

1000
100000000000000000000044444444444444443
1111111111111111111111111111111111111111111111111111111111111111111188888888888888888888888888888888888888
44444444444444499999999999999999999999999999
1111111111111111111111111111111111111111111111111111111111166666666666666666666666666666666666666666666...

output:

44444444444444444 99999999999999999999999999999999999999
77777777777777777777777777777777777777 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
55555555555555555555555555555 44444444444444444444444444444444444444444444
5555555555555555555555...

result:

ok ok (1000 test cases)

Test #6:

score: 0
Accepted
time: 4ms
memory: 3576kb

input:

100
22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (100 test cases)

Test #7:

score: 0
Accepted
time: 4ms
memory: 3700kb

input:

50
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

77777777 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (50 test cases)

Test #8:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

25
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

22222222222222222222222222222222222222222 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (25 test cases)

Test #9:

score: 0
Accepted
time: 2ms
memory: 3572kb

input:

10
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

output:

555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

result:

ok ok (10 test cases)

Test #10:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

1
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

result:

ok ok (1 test case)

Test #11:

score: 0
Accepted
time: 4ms
memory: 3632kb

input:

25
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666...

output:

333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

result:

ok ok (25 test cases)

Test #12:

score: 0
Accepted
time: 4ms
memory: 3696kb

input:

25
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

output:

222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (25 test cases)

Test #13:

score: 0
Accepted
time: 4ms
memory: 3580kb

input:

25
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

result:

ok ok (25 test cases)

Test #14:

score: 0
Accepted
time: 4ms
memory: 3584kb

input:

25
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #15:

score: 0
Accepted
time: 5ms
memory: 3636kb

input:

25
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

result:

ok ok (25 test cases)

Test #16:

score: 0
Accepted
time: 5ms
memory: 3620kb

input:

25
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...

result:

ok ok (25 test cases)

Test #17:

score: 0
Accepted
time: 5ms
memory: 3564kb

input:

25
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

output:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #18:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

25
666666666666666666666666666666666666666666666666666666666666666666666666666666666666888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...

output:

222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (25 test cases)

Test #19:

score: 0
Accepted
time: 5ms
memory: 3696kb

input:

25
777777778111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

result:

ok ok (25 test cases)

Test #20:

score: 0
Accepted
time: 5ms
memory: 3596kb

input:

25
133333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #21:

score: 0
Accepted
time: 6ms
memory: 3700kb

input:

25
877777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #22:

score: 0
Accepted
time: 4ms
memory: 3704kb

input:

25
566666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok ok (25 test cases)

Test #23:

score: 0
Accepted
time: 4ms
memory: 3596kb

input:

25
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

3 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #24:

score: 0
Accepted
time: 4ms
memory: 3560kb

input:

25
899999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok ok (25 test cases)