QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207986#6568. Space AlignmentThallium54#WA 2ms7316kbC++201.9kb2023-10-09 02:21:232023-10-09 02:21:23

Judging History

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

  • [2023-10-09 02:21:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7316kb
  • [2023-10-09 02:21:23]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
 
typedef long long int ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>

 
const int N = 1e5 + 100;
const int inf = 1e9;
const ll mod =  9302023;

int a[N], b[N], d[N];
int n;
string s[N];


inline void check(int x)
{
	int k = -1;
	for(int i = 0; i < n; i++)
	{
		if(d[i] == 0 && b[i] != 0)
		{
			cout << -1 << endl;
			exit(0);
		}
		if(d[i] == 0 && (a[i] == 0 || x == 0))
			continue;
		if(d[i] == 0)
		{
			cout << -1 << endl;
			exit(0);
		}
		//cout << i << ' ' << x << ' ' << d[i] << ' ' << k << endl;
		// d[i] != 0
		if((x*a[i] + b[i])%d[i] != 0)
		{
			cout << -1 << endl;
			exit(0);
		}
		if(k == -1)
		{
			k = (x*a[i] + b[i]) / d[i];
			continue;
		}
		if(k != (x*a[i] + b[i]) / d[i])
		{
			cout << -1 << endl;
			exit(0);
		}
	
	}
	cout << x << endl;
	exit(0);
}


int main()
{
	
	cin >> n;
	int k = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> s[i];
		int m = s[i].size();
		
		if(s[i][m-1] == '}')
			k--;
		for(int j = 0; j < m-1; j++)
		{
			if(s[i][j] == 's')
				b[i]++;
			else
				a[i]++;	
		}
		d[i] = k;
		
		if(s[i][m-1] == '{')
			k++;
			
	}
	
	
	for(int i = 0; i < n; i++)
	{
		if(d[i] == 0)
		{
			if(b[i] != 0)
			{
				cout << -1 << endl;
				exit(0);
			}
			if(a[i] != 0)
			{
				check(0);
			}
			continue;
		}
		for(int j = i+1; j < n; j++)
		{
			if(d[j] == 0)
			{
				if(b[j] != 0)
				{
					cout << -1 << endl;
					exit(0);
				}
				if(a[j] != 0)
				{
					check(0);
				}
				continue;
			}

			
			int A = a[i]*d[j], B = b[i]*d[j];
			int A2 = a[j]*d[i], B2 = b[j]*d[i];
			if(A == A2 && B == B2)
				continue;
			if(A == A2)
			{
				cout << -1 << endl;
				exit(0);
			}	
			
			check((B2-B)/(A-A2));
			
		}
	}
		
	cout << 1 << endl;	
		
		
    return 0;
}





Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7316kb

input:

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

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 2ms
memory: 6660kb

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 7008kb

input:

4
{
tt{
t}
}

output:

0

result:

wrong answer 1st lines differ - expected: '-1', found: '0'