QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#178729#6568. Space Alignmentneko_nyaaAC ✓1ms3552kbC++201.2kb2023-09-14 11:50:592023-09-14 11:50:59

Judging History

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

  • [2023-09-14 11:50:59]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3552kb
  • [2023-09-14 11:50:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int n; cin >> n;
	vector<int> s(n), t(n), lv(n);
	int curlv = 0;
	for (int i = 0; i < n; i++) {
		string str; cin >> str;
		for (char c: str) {
			if (c == 's') s[i]++;
			else if (c == 't') t[i]++;
		}
		if (str.back() == '{') {
			lv[i] = curlv; curlv++;
		} else {
			curlv--; lv[i] = curlv; 
		}
	}

	vector<int> sp(n);
	for (int tv = 1; tv <= 1000; tv++) {
		for (int i = 0; i < n; i++) {
			sp[i] = s[i] + t[i]*tv;
		}
		int spec = -1;
		for (int i = 0; i < n; i++) {
			if (lv[i] > 0) {
				spec = sp[i]/lv[i];
				break;
			}
		}
		
		if (spec == -1) {
			// all sp must be 0
			if (*max_element(sp.begin(), sp.end()) == 0) {
				cout << tv << '\n';
				return 0;
			}
		} else {
			// 1 level = 1 * spec
			bool ok = 1;
			for (int i = 0; i < n; i++) {
				if (lv[i] == 0) {
					if (sp[i] != 0) {
						ok = 0; break;
					}
				} else {
					if (lv[i]*spec != sp[i]) {
						ok = 0; break;
					}
				}
			}
			if (ok) {
				cout << tv << '\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: 1ms
memory: 3552kb

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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: 1ms
memory: 3452kb

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'