QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#251976#5420. InscryptionSarwar82WA 154ms3520kbC++201.7kb2023-11-15 13:55:402023-11-15 13:55:40

Judging History

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

  • [2023-11-15 13:55:40]
  • 评测
  • 测评结果:WA
  • 用时:154ms
  • 内存:3520kb
  • [2023-11-15 13:55:40]
  • 提交

answer

/*If we keep holding onto yesterday, what are we going to be tomorrow?*/


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int 
bool debugg = false;
#define dbg if(debugg)
#define F first 
#define S second 
template <typename T>
using order_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());  


void solve()
{
    int n;
    cin >> n;

    int cnt = 0;

    vector<int>v(n);
    for(int i = 0 ; i < n ; i ++) cin >> v[i];

    int cur = 1 , sum = 1;
    for(int i = 0 ; i < n ; i ++){
        if(v[i] == 1){
            cur ++ , sum ++;
           
            continue;
        }

        if(v[i] == -1){
            if(cur == 1 && cnt == 0){
                cout << -1 << '\n';
                return;
            }

            if(cnt > 0){
                cnt --;
                sum ++;
            }
            else{
                cur --;
            }
            continue;
        }

        else if(v[i] == 0 ) cnt ++;

        
    }
    //cout << "____\n\n";
    while(cnt > 0){
        //cout << cur << ' ' << sum << '\n';
        if(cur > 1){
            cur --;
        }
        else{
            cur ++;
            sum ++;
        }
        cnt --;
    }

    cout << sum / __gcd(sum , cur) << ' ' << cur / __gcd(sum , cur)<< '\n';
}



int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
        
    int t  = 1;
    cin >> t;
    
    while(t--){
        solve();
    }

    return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

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: 154ms
memory: 3452kb

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: 70ms
memory: 3476kb

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 -1 0 1
8
1 -1 -1 -1 0 1 -1 0
2
0 0
3
-1 1 0
3
0 -1 -1
10
0 1 0 -1 1 1 0 -1 1 0
3
1 0 0
9
1 -1 1 -1 0 -1 0 0 0
3
0 1 0
3
-1 0 0
7
-1 0 -1 -1 ...

output:

4 1
-1
-1
3 2
4 1
-1
3 1
-1
3 2
2 1
3 2
-1
-1
2 1
-1
-1
7 3
3 2
3 1
3 2
-1
-1
-1
-1
2 1
6 5
-1
5 4
2 1
-1
3 2
5 1
1 1
-1
3 2
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
3 2
-1
-1
-1
-1
3 2
5 2
1 1
-1
3 1
-1
-1
1 1
-1
6 1
3 2
-1
3 2
4 3
2 1
-1
5 3
7 4
7 3
-1
2 1
5 4
-1
1 1
-1
3 1
-1
-1
5 3
1 1
2 1
5 2
-1
3 1
4 3...

result:

wrong answer 17th lines differ - expected: '6 1', found: '7 3'