QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#228298 | #5420. Inscryption | mobbb# | WA | 372ms | 3528kb | C++17 | 1.3kb | 2023-10-28 13:18:29 | 2023-10-28 13:18:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define double long double
void solve(){
int n;cin >> n;
vector<int> a(n + 1),pos(n + 1),neg(n + 1),zero(n + 1);
int x = 0,y = 0;
for (int i = 1;i <= n;i++){
cin >> a[i];
pos[i] = pos[i - 1] + (a[i] == 1);
neg[i] = neg[i - 1] + (a[i] == -1);
zero[i] = zero[i - 1] + (a[i] == 0);
}
int p = -1,q = 100;
double r = -1;
bool ok = false;
int jue = 0;
for (int i = 1;i <= n;i++){
int t = pos[n] + zero[i] + 1;
int bw = t - (neg[n] - neg[i] + zero[n] - zero[i]);
//if (bw <= 0) continue;
//cout << t << " " << bw << endl;
jue += a[i];
//continue;
if (jue < 0){
break;
}
if (bw == 0) continue;
double xx = 1.0 * t / (bw);
if (xx > r){
r = xx;
int tt = gcd(t,bw);
t /= tt;
bw /= tt;
p = t,q = bw;
}
}
if (r == -1){
cout << -1 << endl;
}else{
cout << p << " " << q << endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;cin >> T;
while (T--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3524kb
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: 372ms
memory: 3528kb
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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