QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#790372 | #5420. Inscryption | TauLee01 | WA | 228ms | 3816kb | C++23 | 4.7kb | 2024-11-28 11:16:16 | 2024-11-28 11:16:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ms(x, y) memset(x, y, sizeof x);
#define debug(x) cout << #x << " = " << x << endl;
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fre \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const double esp = 1e-6;
const ull MOD1 = 1610612741;
const ull MOD2 = 805306457;
const ull BASE1 = 1331;
const ull BASE2 = 131;
#define pre(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
char *p1, *p2, buf[100000]; // 快读和同步流二者只能选一个
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
int read()
{
int x = 0, f = 1;
char ch = nc();
while (ch < 48 || ch > 57)
{
if (ch == '-')
f = -1;
ch = nc();
}
while (ch >= 48 && ch <= 57)
x = x * 10 + ch - 48, ch = nc();
return x * f;
}
void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
void solve()
{
int n;
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> v[i];
}
// int cnt = 0, cnt1 = 0, cnt2 = 0;
vector<int> sum(n + 1);
vector<int> cnt0(n + 1), cnt1(n + 1), cnt2(n + 1);
for (int i = 1; i <= n; i++)
{
sum[i] = sum[i - 1];
if (v[i] == 0 || v[i] == 1)
{
sum[i]++;
}
else
{
sum[i]--;
}
cnt0[i] = cnt0[i - 1];
cnt1[i] = cnt1[i - 1];
cnt2[i] = cnt2[i - 1];
if (v[i] == 0)
{
cnt0[i]++;
}
else if (v[i] == 1)
cnt1[i]++;
else
cnt2[i]++;
}
int p = n + 1;
for (int i = n; i >= 1; i--)
{
if (v[i] == -1)
{
p = i;
if (sum[i] < 0)
{
cout << -1 << endl;
return;
}
break;
}
}
if (p == n + 1)
{
int now = 1;
int num = 1;
for (int i = 1; i <= n; i++)
{
if (v[i] == 1)
{
now++;
num++;
}
else
{
if (num >= 2)
{
num--;
}
else
{
num++;
now++;
}
}
}
int g = gcd(now, num);
cout << now / g << ' ' << num / g << endl;
return;
}
int num1 = 0;
num1 += min(cnt0[p], sum[p]);
int xx1 = cnt1[p] + cnt0[p] - num1; // 1
int xx2 = cnt2[p] + num1; // -1
// cout << p << " " << xx1 << " " << xx2 << endl;
// int x = sum[p];
// cout << "NUM" << num << endl;
int now = xx1 + 1, num = 1 + xx1 - xx2;
// cout << now << " gfd fg d " << cnt << endl;
for (int i = p + 1; i <= n; i++)
{
if (v[i] == 1)
{
now++;
num++;
}
else
{
if (num >= 2)
{
num--;
}
else
{
num++;
now++;
}
}
}
int g = gcd(now, num);
// cout << now << " " << num << endl;
cout << now / g << ' ' << num / g << endl;
// for (int i = p + 1; i <= n; i++)
// {
// if (x == 0 && v[i] == 0)
// {
// num
// }
// else
// {
// num++;
// }
// }
// int a = cnt1 + cnt0[p] - cnt2 - num;
// a++;
// int b = cnt1 + cnt0[p] + 1;
// cout << a << ' ' << b << endl;
// int g = gcd(a, b);
// cout << b / g << ' ' << a / g << endl;
}
// #define LOCAL
signed main()
{
ios
// fre
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
#endif
int t = 1;
cin >> t;
while (t--)
solve();
#ifdef LOCAL
auto end = std::chrono::high_resolution_clock::now();
cout << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << '\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
6 7 1 1 1 -1 1 1 -1 4 1 0 -1 0 4 0 -1 -1 0 1 0 2 0 0 1 -1
output:
3 2 3 1 -1 1 1 2 1 -1
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 228ms
memory: 3816kb
input:
1000000 1 1 1 -1 1 1 1 1 1 1 1 1 1 -1 1 -1 1 0 1 0 1 1 1 0 1 -1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 0 1 1 1 -1 1 1 1 1 1 -1 1 0 1 1 1 0 1 -1 1 0 1 -1 1 1 1 -1 1 0 1 1 1 1 1 -1 1 0 1 -1 1 -1 1 -1 1 -1 1 0 1 0 1 -1 1 0 1 -1 1 0 1 0 1 0 1 0 1 0 1 -1 1 1 1 0 1 0 1 1 1 0 1 -1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 ...
output:
1 1 -1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 -1 -1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 ...
result:
ok 1000000 lines
Test #3:
score: -100
Wrong Answer
time: 88ms
memory: 3616kb
input:
181249 6 1 0 -1 0 1 0 4 1 -1 -1 -1 8 -1 0 0 0 1 -1 1 1 3 0 1 0 6 1 0 -1 1 -1 0 4 1 -1 -1 -1 9 0 1 0 -1 -1 0 -1 0 1 1 -1 3 0 -1 1 5 0 0 1 -1 1 3 1 -1 0 6 -1 0 0 -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