QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114260#6407. Classical A+B ProblemOepelingAC ✓29ms3604kbC++141.4kb2023-06-21 19:36:102023-06-21 19:36:12

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-21 19:36:12]
  • Judged
  • Verdict: AC
  • Time: 29ms
  • Memory: 3604kb
  • [2023-06-21 19:36:10]
  • Submitted

answer

#include <iostream>
#include <vector>

using namespace std;

bool Check(vector<int> v, int a, int b) {
	int r = 0;
	int len_a = 0, len_b = 0;
	bool stopped = false;

	// cerr << a << " " << b << endl;

	for (int i = 0; i < v.size(); i++) {
		int aux = r + a + b;
		// cerr << i << " " << aux << " " << v[i] << endl;
		if (aux % 10 == v[i] && !stopped && (r == 0 || i != v.size() - 1)) {
			r = aux / 10;
			len_a++;
			len_b++;
			// cerr << "linia 19" << endl;
		} else {
			aux = r + b;
			if (aux % 10 == v[i]) {
				len_b++;
				r = aux / 10;
				stopped = true;
				// cerr << "linia 27" << endl;
			} else if (r == v[i] && i == v.size() - 1) {
				r = 0;
				// cerr << "linia 29" << endl;
				continue;
			} else {
				// cerr << "linia 33" << endl;
				return false;
			}
		}
	}

	if (r != 0) {
		return false;
	}

	cout << string(len_a, a + '0') << " " << string(len_b, b + '0') << '\n';
	return true;
}

void Solve() {
	string n; cin >> n;
	vector<int> v;

	for (int i = n.size() - 1; i >= 0; i--) {
		v.push_back(n[i] - '0');
	}

	for (int i = 1; i < 10; i++) {
		int j = (10 + v[0] - i) % 10;
		if (j == 0) { continue; }
		if (Check(v, i, j)) {
			break;
		}
	}
}

int main() {
	int t; cin >> t;
	for (int i = 0; i < t; i++) {
		Solve();
	}
}

/*
6
2
786
1332
89110
2333333
10000000000000000000000000001

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

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

result:

ok ok (6 test cases)

Test #2:

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

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
1 4
9999 333333333333333333333333333
111 888888
1 9
2222 11111111
2 333
2 77777
222222222222222222222 88888888888888888888888888888888888888888888
222222 55555555555555555555
5555555555555555555555 6666...

result:

ok ok (100 test cases)

Test #3:

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

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:

111111 888888
88 1111
3 888888
11 33333333333
1 5
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: 29ms
memory: 3504kb

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
11 88
999999 5555555
1 9
1 4
33333 222222222222
555 2222
1 7
2 777777
44444444 3333333333333333333
11 66
999999 666666666
11 99
1 8
11111111111 77777777777777777...

result:

ok ok (10000 test cases)

Test #5:

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

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: 5ms
memory: 3496kb

input:

100
22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (100 test cases)

Test #7:

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

input:

50
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

77777777 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (50 test cases)

Test #8:

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

input:

25
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

22222222222222222222222222222222222222222 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (25 test cases)

Test #9:

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

input:

10
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

output:

555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

result:

ok ok (10 test cases)

Test #10:

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

input:

1
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

result:

ok ok (1 test case)

Test #11:

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

input:

25
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666...

output:

333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

result:

ok ok (25 test cases)

Test #12:

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

input:

25
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

output:

222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (25 test cases)

Test #13:

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

input:

25
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

result:

ok ok (25 test cases)

Test #14:

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

input:

25
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #15:

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

input:

25
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

result:

ok ok (25 test cases)

Test #16:

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

input:

25
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...

result:

ok ok (25 test cases)

Test #17:

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

input:

25
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...

output:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #18:

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

input:

25
666666666666666666666666666666666666666666666666666666666666666666666666666666666666888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...

output:

222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result:

ok ok (25 test cases)

Test #19:

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

input:

25
777777778111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

result:

ok ok (25 test cases)

Test #20:

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

input:

25
133333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

result:

ok ok (25 test cases)

Test #21:

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

input:

25
877777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #22:

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

input:

25
566666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok ok (25 test cases)

Test #23:

score: 0
Accepted
time: 3ms
memory: 3520kb

input:

25
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

3 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok ok (25 test cases)

Test #24:

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

input:

25
899999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok ok (25 test cases)