QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278633#6568. Space Alignmentucup-team191#AC ✓0ms4148kbC++14959b2023-12-07 18:47:462023-12-07 18:47:47

Judging History

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

  • [2023-12-07 18:47:47]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:4148kb
  • [2023-12-07 18:47:46]
  • 提交

answer

#include <cstdio>
#include <iostream>

using namespace std;

const int N = 1050;

int n, x_s[N], x_t[N], dep[N];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	int depth = 0;
	for(int i = 0;i < n;i++) {
		string s; cin >> s;
		if(s.back() == '}') depth--;
		for(char c : s) x_s[i] += c == 's', x_t[i] += c == 't';
		
		if(depth == 0 && x_s[i] + x_t[i] != 0) {
			printf("-1\n");
			return 0;
		}
		if(depth != 0 && x_s[i] + x_t[i] == 0) {
			printf("-1\n");
			return 0;
		}
		dep[i] = depth;
		if(s.back() == '{') depth++;
	}
	int poc = 0;
	while(poc < n && dep[poc] == 0) poc++;
	if(poc == n) {
		printf("1\n");
		return 0;
	}
	for(int t = 1;t <= 1010;t++) {
		int ind = (x_s[poc] + t * x_t[poc]) / dep[poc];
		int ret = 1;
		for(int i = 0;i < n;i++)
			ret &= (x_s[i] + t * x_t[i]) == dep[i] * ind;
		if(ret) {
			printf("%d\n", t);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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: 3792kb

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'