QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#240910#6568. Space AlignmentMovingUp#AC ✓0ms3820kbC++141.2kb2023-11-05 20:54:262023-11-05 20:54:26

Judging History

你现在查看的是最新测评结果

  • [2023-11-05 20:54:26]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3820kb
  • [2023-11-05 20:54:26]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 5e5 + 10;
const int mod = 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	vector<string> v(n);
	vector<int> level(n), cnt_s(n), cnt_t(n);
	int cur_level = -1;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		for (char& ch : v[i]) {
			if (ch == 's') {
				cnt_s[i]++;
			} else if (ch == 't') {
				cnt_t[i]++;
			}
		}
		if (v[i].back() == '{') {
			cur_level++;
			level[i] = cur_level;
		} else {
			level[i] = cur_level;
			cur_level--;
		}
		// cout << level[i] << " " << cnt_s[i] << " " << cnt_t[i] << "\n";
	}

	for (int spaces = 1; spaces <= 2000; spaces++) {
		int k = -1;
		bool check = true;
		for (int i = 0; i < n; i++) {
			int cnt = cnt_s[i] + cnt_t[i] * spaces;
			if (level[i] == 0) {
				if (cnt != 0) {
					check = false;
					break;
				}
			} else {
				if (cnt % level[i] != 0 || (k != -1 && cnt / level[i] != k)) {
					check = false;
					break;
				}
				k = cnt / level[i];
			}
		}

		if (check) {
			cout << spaces << "\n";
			return 0;
		}
	}

	cout << "-1\n";
 	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10
{
ss{
sts{
tt}
t}
t{
ss}
}
{
}

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

input:

100
{
}
{
}
{
t{
ssssssssssssssssssssssssssssssssssss}
t{
t}
t{
tssssssssssssssssssssssssssssssssssss{
tssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss{
tsssssssssssssssssssssssssssssssssssst}
ttssssssssssssssssssssssssssssssssssss{
ssssssssssssssssssssssssssssssssssssssssss...

output:

36

result:

ok single line: '36'

Test #12:

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

input:

100
{
t{
tssssssssssssssssssss{
ttssssssssssssssssssss{
tsssssssssssssssssssstt{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{
ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'