QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743087#9477. Topological SortP-BaoWA 0ms3776kbC++231.0kb2024-11-13 18:11:242024-11-13 18:11:25

Judging History

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

  • [2024-11-13 18:11:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3776kb
  • [2024-11-13 18:11:24]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long
#define mod 998244353

using namespace std;

ll fastpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    
    stack<int> st;                  // st.top(): chỉ số lớn nhất không cho phép có đường từ a[i] đến
    ll res = 1;
    for(int i = 0; i < n; ++i){
        while(!st.empty() && a[st.top()] < a[i]) st.pop();

        // Mỗi vị trí có 2 lựa chon: nối hoặc không
        if(st.empty()) res *= fastpow(2, i);        
        else res *= (fastpow(2, i) - fastpow(2, st.top()));
        res %= mod;
        
        st.push(i);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.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: 3776kb

input:

3
1 3 2

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

5
1 2 3 4 5

output:

1024

result:

ok "1024"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

6
4 2 1 5 6 3

output:

4096

result:

ok "4096"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3496kb

input:

492
397 486 227 395 58 452 172 216 130 181 268 482 85 209 365 104 373 90 260 326 252 96 267 106 102 398 441 41 292 314 12 78 242 353 153 424 179 86 299 228 54 390 73 465 396 349 4 10 451 99 342 250 391 6 323 197 159 47 136 473 392 77 125 362 418 255 291 13 238 339 8 28 413 121 384 157 152 23 221 305...

output:

-924815411

result:

wrong answer 1st words differ - expected: '73428942', found: '-924815411'