QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359355#6568. Space Alignmentnkamzabek#AC ✓8ms5936kbC++231.4kb2024-03-20 16:55:142024-03-20 16:55:15

Judging History

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

  • [2024-03-20 16:55:15]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:5936kb
  • [2024-03-20 16:55:14]
  • 提交

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define sz(s) (int)s.size()
#define int long long

using namespace std;

const int N = (int)5e5 + 100;
const int M = N + 7;
const int MOD = 998244353;
const int INF = (int)1e18 + 100;


int n, cnt[N][2], c[N];

main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    cin >> n;
    int bal = 0;
    set<int> u;
    for(int i = 1; i <= n; i++){
    	string s;
        cin >> s;
        int d = 1;
        for(auto x : s){
            if(x == 's')
                cnt[i][0]++;
            if(x == 't')
                cnt[i][1]++;
            if(x == '{')
                d = 1;
            else
                d = -1;
        }
        if(d == -1) bal += d;
        c[i] = bal;
        if(d == 1) bal += d;
    }
    int ans = INT_MAX;
    for(int C = 1; C <= 1000000; C++){
    	bool bad=0;
    	int target = -1;
    	for(int i = 1; i <= n && !bad; i++){
    		int rem = C*c[i] - cnt[i][0];
    		if(rem < 0) bad = 1;
    		if(!cnt[i][1]){
    		    if(rem != 0)
    		    	bad = 1;
    			continue;
    		}
    		if(rem % cnt[i][1]) bad = 1;
    		if(target == -1){
    			target = rem / cnt[i][1];
    		}
    		if(rem / cnt[i][1] != target){
    			bad = 1;
    		}
    	}
    	if(!bad){
    		if(target == -1) target = 1;
    		ans = min(ans, target);
    	}
    }
    if(ans == INT_MAX) ans = -1;
    cout << ans << "\n";

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5932kb

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 8ms
memory: 5728kb

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'