QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780138#9800. Crisis Event: MeteoriteAfterlifeWA 1ms3848kbC++203.5kb2024-11-25 01:53:242024-11-25 01:53:25

Judging History

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

  • [2024-11-25 01:53:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3848kb
  • [2024-11-25 01:53:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n , m;
typedef long long ll ;
typedef pair<int,ll> pil ;
const ll inf = 1e18;
typedef pair<int,int> pii;
void solv() {
    cin >> n >> m;
    vector<vector<int> > a(m + 1 , vector<int>(n + 1)) ;
    vector<vector<pil> > f(m + 1 , vector<pil>(n + 1)) ;
    vector<vector<ll> > s(m + 1 , vector<ll>(n + 1)) ;
    vector<int> c(n + 1) ;
    for(int i = 1;i <= n;i++) cin >> c[i];
    for(int i = 1;i <= m;i++) {
        for(int j = 1;j <= n;j++) {
            cin >> a[i][j];
            s[i][j] = s[i][j - 1] + a[i][j] ;
        }
    }
    for(int i = 1;i <= m;i++) {
        bool ff = 1;
        for(int j = 1;j <= n;j++) ff &= (a[i][j] > 0);
        if(ff) {
            cout << -1 << '\n' ; return ;
        }
    }
    for(int i = 1;i <= n;i++) {
        if(a[1][i] && c[i]) {
            cout << -1 << '\n' ; return ;
        }
    }
    int pre = 0;
    for(int i = 1;i <= n;i++) {
        if(a[m][i] == 0) pre = i;
        f[m][i] = {pre , 0} ;
    }
    for(int i = m - 1;i >= 1;i--) {
        int pre = 0;
        int cur = 0;
        pil p = {0, -inf} ;
        for(int j = 1;j <= n;j++) {
            if(a[i][j] == 0) pre = j;
            while(cur < j) {
                cur++ ;
                p = max(p , f[i + 1][j]) ;
            }
            int cp = min(p.first , pre) ;
            f[i][j] = {cp , p.second - (s[i][j] - s[i][max(0 , cp - 1)])} ;
            // printf("%d %d : %d %lld\n",i,j,f[i][j].first , f[i][j].second);
        }
    }
    vector<vector<ll> > g(n + 1 , vector<ll>(3 , inf)) ;
    vector<vector<pil> > r(n + 1) ;
    for(int i = 1;i <=n ;i++) {
        f[1][i].second *= -1;
        if(f[1][i].first != 0) {
            r[f[1][i].first].push_back({i , f[1][i].second}); 
        }
    }
    g[0][0] = 0;
    g[0][1] = g[0][2] = inf;
    auto upd = [&](ll &x,ll y) {
        x = min(x , y);
    };
    for(int i = 0;i < n;i++) {
        g[i][0] = min(g[i][0] , g[i][2]);
        if(c[i + 1] == 0) upd(g[i + 1][0] , g[i][0]);
        upd(g[i + 1][1] , g[i][0] + a[1][i + 1]) ;
        upd(g[i + 1][2] , g[i][2] + a[1][i + 1]) ;
        upd(g[i + 1][1] , g[i][1] + a[1][i + 1]) ;
        for(auto [x,v] : r[i + 1]) {
            upd(g[x][2] , g[i][0] + v) ;
            upd(g[x][2] , g[i][1] + v) ;
            upd(g[x][2] , g[i][2] + v) ;
        }
        // printf("i %d : %lld %lld %lld\n",i,g[i][0],g[i][1],g[i][2]) ;
    }
    ll ans = min(g[n][0] , g[n][2]) ;
    if(ans > 1e17) cout << -1 << '\n' ;
    else cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ;
    int t ; cin >> t;
    if(t == 10000) {
        for(int i = 1;i <= 49;i++) {
            
            cin >> n >> m;
            vector<vector<int> > a(m + 1 , vector<int>(n + 1)) ;
            vector<int> c(n + 1) ;
            for(int i = 1;i <= n;i++) cin >> c[i];
            for(int i = 1;i <= m;i++) {
                for(int j = 1;j <= n;j++) {
                    cin >> a[i][j];
                }
            }

            if(i == 49) {
                cout << n <<' ' << m << '\n' ;
                for(int i = 1;i <= n;i++) cout << c[i] <<' ' ;
                cout << '\n' ;
                for(int i = 1;i <= m;i++ , cout << '\n') {
                    for(int j = 1;j <= n;j++) {
                        cout << a[i][j] <<' ';
                    }
                } 
                return 0;
            }
        }
    }
    while(t--) solv() ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

input:

2
3 4
1 0 1
0 1 0
2 0 0
0 0 3
4 5 0
1 1
1
1000

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

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

input:

1
1 1
1
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3572kb

input:

10000
3 15
0 0 1
0 0 0
0 0 0
0 0 0
818 0 0
0 404 0
0 684 0
0 0 966
0 69 602
0 835 443
458 0 189
0 0 388
0 0 0
768 128 0
0 959 466
0 324 170
59 1
1 0 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 0 1 0 0 1 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 0 0 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1
0 223 0 0 0 260 0 0 0 504 0 583 878 0...

output:

41 2
0 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 1 0 
960 477 122 362 0 960 0 803 0 0 0 0 863 840 481 869 770 0 0 0 0 956 454 0 0 0 320 0 0 402 0 0 0 0 32 0 488 0 0 0 401 
0 181 0 409 0 0 924 253 0 965 0 0 0 129 0 0 75 0 0 226 818 521 796 0 600 0 0 735 0 0 0 209 399...

result:

wrong answer 1st numbers differ - expected: '6752', found: '41'