QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117399#6568. Space AlignmentUNos_maricones#AC ✓3ms3492kbC++201.4kb2023-07-01 04:40:232023-07-01 04:40:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 04:40:23]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3492kb
  • [2023-07-01 04:40:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "../debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



#define pb push_back

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	long long n; cin >> n;
	long long curdep = 0;
	
	vector <vector<long long>> eqs;

	for (long long i = 0; i < n; ++i) { 
		string s; cin >> s;
	//	cout << s << endl;
		long long nwtab = 0, nwdep = curdep, nwe = 0;
		if (s.back() == '{') curdep++;
		else curdep--, nwdep--;
		
		for (long long j = 0; j + 1 < s.size(); ++j) { 
			if (s[j] == 't') nwtab++;
			else nwe++;
		}

		
		eqs.pb({nwtab, nwdep, nwe});	
	}

	for (long long i = 1; i <= 300000; ++i) { 
		long long impo = 0;
		long long Ri = -1;
		for (long long j = 0; j < n; ++j) { 
			long long posi = 0;
			//cout << eqs[j][0] << ' ' << eqs[j][1] << ' ' << eqs[j][2] << '\n';
			if (eqs[j][1] == 0) { 
				if (eqs[j][0] || eqs[j][2]) impo = 1;
			}
			else {
				if ((i * eqs[j][0] + eqs[j][2]) % eqs[j][1]) impo = 1;
				else {
					posi = (i * eqs[j][0] + eqs[j][2]) / eqs[j][1];
					if (Ri == -1) Ri = posi;
					if (Ri != posi) impo = 1;
				//  cout << "in " << j << ' ' << posi << '\n';
				}
			}
			
		}
		//cout << Ri << '\n';
		if (!impo) { 
			cout << i << '\n';
			break;
		}
		if (i == 300000) cout << -1 << '\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'