QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#207985 | #6568. Space Alignment | Thallium54# | WA | 1ms | 7632kb | C++20 | 1.9kb | 2023-10-09 02:17:46 | 2023-10-09 02:17:46 |
Judging History
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7296kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 6792kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6784kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6908kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 6780kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 7632kb
input:
4 { tt{ t} }
output:
0
result:
wrong answer 1st lines differ - expected: '-1', found: '0'