QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277044 | #6568. Space Alignment | ucup-team1198# | WA | 0ms | 3436kb | C++14 | 2.2kb | 2023-12-06 14:54:29 | 2023-12-06 14:54:30 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#endif
int n;
cin >> n;
int s1 = -1, t1 = -1, k1 = -1;
int k2 = 0;
int x = -1, y = -1;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s.back() == '}') --k2;
if (i != 0 && i != n - 1) {
int s2 = 0, t2 = 0;
for (auto ch : s) {
if (ch == 's') ++s2;
if (ch == 't') ++t2;
}
/// cerr << s2 << " " << t2 << " " << k2 << endl;
/// cerr << x << " " << y << endl;
if (x != -1) {
if (s2 + t2 * x != k2 * y) {
cout << "-1\n";
return 0;
}
} else {
if (s2 != 0 || t2 != 0 || k2 != 0) {
if (s1 == -1) {
s1 = s2;
t1 = t2;
k1 = k2;
}
int det = k1 * t2 - k2 * t1;
int detx = s1 * k2 - k1 * s2;
int dety = s1 * t2 - t1 * s2;
if (det == 0) {
if (detx != 0 || dety != 0) {
cout << "-1\n";
return 0;
}
} else {
if (detx % det != 0 || dety % det != 0) {
cout << "-1\n";
return 0;
}
x = detx / det;
y = dety / det;
if (x <= 0 || y <= 0) {
cout << "-1\n";
return 0;
}
}
}
}
}
if (s.back() == '{') {
++k2;
}
}
if (x != -1) {
cout << x << "\n";
} else if (s1 != 0) {
if (s1 == 0 && t1 == 0) {
cout << "-1\n";
return 0;
}
for (int x = 1; x <= k1; ++x) {
if ((s1 + t1 * x) % k1 == 0) {
cout << x << "\n";
return 0;
}
}
cout << "-1\n";
} else {
cout << "1\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3436kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3436kb
input:
2 { }
output:
-1
result:
wrong answer 1st lines differ - expected: '1', found: '-1'