QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623828#7057. Digital PathtravelAC ✓91ms100076kbC++142.2kb2024-10-09 14:08:072024-10-09 14:08:11

Judging History

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

  • [2024-10-09 14:08:11]
  • 评测
  • 测评结果:AC
  • 用时:91ms
  • 内存:100076kb
  • [2024-10-09 14:08:07]
  • 提交

answer

//
// Created by travel on 2024/10/9.
//
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> PII;
#define endl "\n"
#define ft first
#define sd second
#define pb push_back
const int MOD = 1e9 + 7;
int n,m;
const int N = 1e6 + 10;
int h[N],e[N << 2],ne[N << 2],idx;
int in[N],dp[N][5];
int id(int a,int b){
    return (a - 1) * m + b;
}
int g[1010][1010];
int dx[] = {0,0,-1,1},dy[] = {1,-1,0,0};
void add(int a,int b){
    e[idx] = b,ne[idx] = h[a],h[a] = idx++;
}

void solve(){
    memset(h,-1,sizeof h);
    cin>>n>>m;
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++)
            cin>>g[i][j];
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            for(int k = 0;k < 4;k++){
                int x = dx[k] + i,y = dy[k] + j;
                if(x >= 1 && x <= n && y >= 1 && y <= m){
                    if(g[i][j] == g[x][y] - 1){
                        int id1 = id(i,j),id2 = id(x,y);
                        add(id1,id2);
                        in[id2]++;
                    }
                }
            }
        }
    }
    queue<int> q;
    int res = 0;
    for(int i = 1;i <=n;i++){
        for(int j = 1;j <= m;j++){
            int x = id(i,j);
            if(!in[x]) {
//                cout<<i<<' '<<j<<' '<<x<<endl;
                q.push(x);
                dp[x][1] = 1;
            }
        }
    }
    while(q.size()){
        int t = q.front();
        q.pop();
        bool flag = 1;
        for(int i = h[t];~i;i = ne[i]){
            int j = e[i];
            dp[j][2] = (dp[j][2] + dp[t][1]) % MOD;
            dp[j][3] = (dp[j][3] + dp[t][2]) % MOD;
            dp[j][4] = (dp[j][4] + dp[t][3] + dp[t][4]) % MOD;
            flag = 0;
            if(--in[j] == 0)
                q.push(j);
        }
        if(flag)
            res = (res + dp[t][4]) % MOD;
//        cout<<"flag = "<<flag<<' '<<t<<' '<<dp[t][4]<<endl;
    }
    cout<<res<<endl;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    while(T--)
        solve();
    return 0;
}
/*
 *
3 5
 1 2 3 8 7
 -1 -1 4 5 6
 1 2 3 8 7

 4 4
 1 2 3 4
 2 3 4 3
 3 4 3 2
 4 3 2 1
 */

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4

result:

ok single line: '4'

Test #2:

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

input:

4 4
1 2 3 4
2 3 4 3
3 4 3 2
4 3 2 1

output:

16

result:

ok single line: '16'

Test #3:

score: 0
Accepted
time: 74ms
memory: 91596kb

input:

1000 1000
1000000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 ...

output:

990039586

result:

ok single line: '990039586'

Test #4:

score: 0
Accepted
time: 8ms
memory: 24316kb

input:

146 237
1 1 1 1 1 1 2 3 4 5 1 1 4 1 1 2 3 1 1 1 2 1 1 1 4 1 1 2 3 4 5 6 7 1 1 1 1 2 3 1 2 3 1 2 3 6 7 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 2 3 1 2 3 1 1 2 1 1 1 2 1 2 3 4 1 1 1 2 1 2 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 3 4 5 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 2 3 1 1 1 1 ...

output:

152287

result:

ok single line: '152287'

Test #5:

score: 0
Accepted
time: 12ms
memory: 31900kb

input:

211 597
1 1 2 1 2 3 4 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 2 3 1 1 1 1 1 2 3 4 1 4 5 6 1 2 1 2 1 1 1 1 2 3 6 1 1 2 1 2 1 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 3 4 1 1 2 1 1 2 1 1 1 1 1 1 2 1 4 5 1 2 3 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 3 4 1 1 1 2 3 1 2 1 2 3 1 1 1 1 1 ...

output:

399561

result:

ok single line: '399561'

Test #6:

score: 0
Accepted
time: 13ms
memory: 29736kb

input:

231 551
1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 3 1 1 1 1 2 1 1 9 8 1 2 1 1 1 1 1 1 2 3 1 1 2 1 1 1 1 2 1 1 1 2 3 1 1 1 2 1 1 1 1 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 6 1 2 3 4 1 1 2 1 1 2 1 1 1 1 2 3 1 1 2 1 6 1 2 5 6 1 1 2 3 1 2 3 4 1 1 2 1 1 1 2 1 1 2 1 2 1 2 3 1 1 2 1 6 7 1 2 1 1 2 1 1 1 1 2 1 1 2 1 ...

output:

1188595

result:

ok single line: '1188595'

Test #7:

score: 0
Accepted
time: 15ms
memory: 34120kb

input:

342 549
1 1 1 1 1 1 1 1 1 2 3 1 1 2 1 1 1 1 1 2 5 1 1 2 3 4 1 2 1 1 2 1 1 1 2 1 1 2 1 1 2 3 1 2 3 1 2 3 1 1 1 1 1 2 3 6 1 1 1 1 4 1 4 5 6 7 8 1 1 2 3 1 1 1 2 3 4 5 6 7 1 1 1 1 1 1 1 2 3 1 1 1 1 1 1 1 2 3 4 1 1 1 2 3 4 5 6 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 1 1 2 3 4 1 1 1 1 1 1 1 1 5 6 1 1 1 1 1 1 1 ...

output:

628608

result:

ok single line: '628608'

Test #8:

score: 0
Accepted
time: 2ms
memory: 21952kb

input:

352 26
1 2 3 1 1 2 3 1 1 2 1 1 1 1 1 1 2 3 1 4 1 1 1 1 1 1
1 1 4 5 1 1 4 1 1 3 4 5 6 3 2 4 3 1 2 3 4 1 1 1 1 2
1 1 1 6 2 6 5 1 13 1 9 8 7 4 3 1 1 1 2 6 5 1 2 1 1 3
2 1 1 2 3 7 6 1 12 11 10 1 1 5 6 2 1 1 1 7 1 1 3 1 2 4
1 1 1 1 4 8 1 2 13 1 11 1 9 8 7 1 1 12 11 8 1 2 4 5 1 2
3 2 3 4 1 1 1 1 1 2 3 11 ...

output:

10827

result:

ok single line: '10827'

Test #9:

score: 0
Accepted
time: 8ms
memory: 26220kb

input:

365 252
1 1 1 1 1 1 1 2 1 1 2 1 2 1 1 1 1 1 1 2 3 6 1 1 4 5 1 2 3 1 1 1 1 1 2 1 2 1 1 1 1 2 3 1 1 1 1 1 1 1 1 1 2 3 1 2 3 4 5 1 1 1 2 1 1 1 1 1 1 2 3 1 2 1 1 1 1 1 1 2 1 1 1 2 3 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 2 3 4 5 6 1 2 3 1 1 1 1 1 1 2 3 4 5 1 1 1 2 1 1 1 2 1 2 3 4 5 ...

output:

166369

result:

ok single line: '166369'

Test #10:

score: 0
Accepted
time: 8ms
memory: 35500kb

input:

185 914
1 1 1 1 1 1 1 1 1 2 3 4 1 1 9 1 1 1 1 1 1 1 2 1 1 2 3 4 5 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 3 1 1 2 1 2 1 1 1 1 2 1 2 3 1 1 1 1 2 3 4 1 1 1 2 3 4 1 2 1 1 2 1 2 3 4 1 2 1 2 3 1 1 1 1 2 1 1 1 1 2 1 2 1 1 2 3 4 1 2 1 1 1 1 1 1 2 1 1 1 2 1 2 7 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 3 1 1 1 2 1 1 ...

output:

486846

result:

ok single line: '486846'

Test #11:

score: 0
Accepted
time: 16ms
memory: 33348kb

input:

381 458
1 1 2 3 1 1 2 3 4 5 1 2 3 4 5 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 2 1 2 3 4 1 1 1 1 2 3 1 2 1 1 2 3 4 1 2 3 4 1 2 1 1 2 1 1 1 2 3 4 1 2 1 1 1 1 1 1 2 3 4 7 1 1 1 4 5 1 1 1 1 1 2 3 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1 1 2 5 6 7 1 2 1 1 1 2 3 1 2 1 1 1 1 1 1 2 1 1 2 3 1 2 3 4 1 1 1 1 1 ...

output:

877099

result:

ok single line: '877099'

Test #12:

score: 0
Accepted
time: 17ms
memory: 29812kb

input:

401 412
1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 2 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 2 3 1 1 1 2 1 2 1 1 1 1 1 5 6 1 1 1 1 2 1 1 2 5 6 7 8 1 1 1 1 1 2 3 1 1 2 3 1 1 1 1 2 1 1 1 1 4 5 1 1 1 2 3 4 1 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 2 3 4 1 ...

output:

710978

result:

ok single line: '710978'

Test #13:

score: 0
Accepted
time: 25ms
memory: 39172kb

input:

414 638
1 1 1 1 1 2 3 4 1 1 1 1 2 3 4 5 8 9 1 1 1 1 1 1 2 3 4 5 1 1 1 1 2 5 1 1 1 1 2 3 4 5 6 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 1 1 1 2 3 1 1 1 2 3 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 2 3 1 1 2 1 1 1 1 1 2 3 1 1 1 1 2 3 1 2 1 1 1 1 4 5 6 1 1 1 4 1 2 1 1 1 1 1 1 1 1 1 1 1 ...

output:

3603480

result:

ok single line: '3603480'

Test #14:

score: 0
Accepted
time: 7ms
memory: 26060kb

input:

424 115
1 1 1 1 1 2 1 1 2 3 1 1 1 2 3 6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 8 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 3 1 1 1 1 2 3 4 1 1 1 1 1 2 1 2 1 1 1 1 2 3 6 1 1 1 1 1 1 9 1 2 3 4 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 3 4 5 1 1 1 2
1 2 3 1 2 3 2 3 1 2 3 2 1 1 4 5 2 2 2 1 2 3 4 5 2 2 1 1 1 1 1 ...

output:

229311

result:

ok single line: '229311'

Test #15:

score: 0
Accepted
time: 21ms
memory: 42684kb

input:

437 573
1 1 2 1 1 2 3 1 1 2 3 4 1 1 7 8 9 1 1 1 1 2 1 1 1 2 1 1 2 3 1 1 1 1 1 1 1 1 2 1 1 1 1 2 3 4 1 1 1 4 1 2 3 4 1 2 3 1 1 2 1 2 5 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 3 1 2 1 1 1 1 1 1 1 2 3 4 5 6 13 12 1 1 1 1 1 1 2 3 4 1 2 1 2 1 2 1 2 1 4 1 2 1 2 3 4 1 1 1 2 1 1 2 1 1 1 1 2 1 1 1 2 5 1 ...

output:

1124492

result:

ok single line: '1124492'

Test #16:

score: 0
Accepted
time: 3ms
memory: 24172kb

input:

446 50
1 2 3 4 1 1 2 1 6 7 8 1 1 1 2 1 1 2 1 2 1 4 1 1 1 1 1 1 1 2 1 2 5 1 1 2 3 4 1 1 2 1 1 2 1 1 1 1 1 1
1 2 3 3 2 7 3 4 5 1 1 1 1 1 2 1 1 3 4 3 2 3 4 2 3 2 2 2 1 2 1 3 4 1 2 3 4 5 6 1 1 2 3 1 2 2 1 2 2 5
1 1 1 4 5 6 4 5 6 7 2 2 3 1 3 2 2 4 5 1 1 1 5 6 7 8 11 12 13 3 4 5 1 2 3 4 9 10 11 2 1 3 4 5 ...

output:

31752

result:

ok single line: '31752'

Test #17:

score: 0
Accepted
time: 25ms
memory: 37492kb

input:

456 527
1 1 1 2 1 2 3 1 2 1 2 1 1 1 2 5 6 7 1 1 1 4 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 13 1 2 3 4 7 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 3 1 1 1 1 1 2 3 1 1 1 1 1 1 1 2 1 1 1 2 3 1 2 3 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 2 1 2 3 1 2 1 2 1 2 1 2 1 1 1 2 3 4 1 6 1 1 1 1 1 1 1 1 1 2 3 4 1 1 1 1 1 1...

output:

743785

result:

ok single line: '743785'

Test #18:

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

input:

466 4
1 2 3 4
1 1 1 5
2 1 1 6
1 1 1 1
2 3 1 1
1 4 1 2
1 2 1 1
4 3 1 2
5 4 1 1
1 5 2 1
1 2 3 1
1 1 4 5
2 1 2 1
1 4 3 2
10 5 6 3
9 8 7 8
1 1 1 9
1 2 11 10
1 3 4 5
2 1 1 2
3 2 1 3
1 2 2 1
1 1 3 1
1 2 4 5
2 10 7 6
1 9 8 1
2 1 1 2
3 4 1 1
4 5 6 1
9 8 7 8
10 1 8 9
11 2 1 10
1 2 1 1
1 3 1 1
1 4 2 1
1 5 6 1...

output:

719

result:

ok single line: '719'

Test #19:

score: 0
Accepted
time: 38ms
memory: 52500kb

input:

482 978
1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 2 1 4 5 1 2 3 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 3 4 5 1 1 1 1 2 3 6 7 1 1 1 1 1 1 1 1 2 3 4 5 1 1 1 1 1 2 3 6 7 8 1 1 1 1 1 1 1 2 3 1 1 1 1 2 3 1 1 2 3 1 1 2 1 1 1 1 1 2 3 1 1 4 5 1 2 1 1 1 2 3 4 1 2 3 1 1 1 1 1 1 1 2 1 1 2 1 1 2 1 2 1 1 ...

output:

1819069

result:

ok single line: '1819069'

Test #20:

score: 0
Accepted
time: 12ms
memory: 26976kb

input:

499 185
1 1 1 1 1 2 3 4 5 8 1 1 1 2 1 2 1 2 3 4 5 6 1 1 1 1 2 3 4 1 1 1 1 1 1 1 1 2 3 1 1 2 1 1 2 3 1 1 2 3 1 1 1 1 1 1 1 1 4 1 2 3 1 1 2 3 4 5 6 7 1 1 1 1 1 1 1 2 1 1 2 1 2 1 1 1 1 1 1 2 1 1 2 3 1 1 2 1 1 1 1 2 6 7 10 11 12 13 14 15 1 1 1 1 1 1 1 2 3 4 5 6 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 2 1 1 2 3 ...

output:

521236

result:

ok single line: '521236'

Test #21:

score: 0
Accepted
time: 7ms
memory: 26668kb

input:

518 139
1 1 1 1 1 1 1 1 1 1 2 3 4 1 1 1 1 1 1 1 1 2 3 4 1 1 1 1 4 1 4 5 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 5 1 2 1 1 2 1 2 3 1 1 1 1 2 1 1 2 1 1 2 3 1 1 1 4 5 6 1 2 3 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 3 7 1 1 1 1 1 1 1 1 1 1 2 3 4 1 1 9 1 1 1 1 1 1 1 2 1 1 2 3 4 5 1 1 1
1 1 1 1 2 1 1 ...

output:

252133

result:

ok single line: '252133'

Test #22:

score: 0
Accepted
time: 42ms
memory: 57216kb

input:

541 842
1 2 1 2 1 4 1 1 1 2 3 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1 1 2 3 1 2 3 1 1 1 2 3 1 1 2 1 2 5 6 7 10 11 12 13 1 1 1 1 2 1 2 3 6 1 2 3 1 2 1 2 1 1 2 1 1 2 1 1 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 2 3 4 1 1 2 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1 1 1 1 1 2 1 1 1 1 2 1 2 3 1 1 1 2 1 1 2 3 1 1 ...

output:

16501983

result:

ok single line: '16501983'

Test #23:

score: 0
Accepted
time: 30ms
memory: 43940kb

input:

587 479
1 1 1 1 1 1 2 3 4 1 2 3 1 2 1 2 3 4 1 1 6 1 1 1 1 2 1 1 1 2 5 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 2 3 4 5 6 1 2 1 2 1 1 1 1 1 1 1 4 5 1 1 1 1 1 2 3 1 2 1 1 1 1 1 1 2 1 1 2 3 4 5 6 1 1 2 5 6 7 1 1 1 2 3 4 5 6 7 1 1 2 3 1 2 3 1 1 1 1 1 2 1 1 1 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 4 ...

output:

1050750

result:

ok single line: '1050750'

Test #24:

score: 0
Accepted
time: 30ms
memory: 39956kb

input:

606 434
1 1 1 2 3 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 2 3 4 1 1 1 1 1 1 1 1 2 1 1 2 1 1 2 3 4 5 6 1 1 1 1 1 2 3 4 5 6 1 1 1 1 1 1 1 2 1 1 2 1 1 2 3 1 1 2 3 1 1 4 1 2 1 1 1 1 1 1 2 1 1 1 2 3 4 1 1 2 3 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 3 1 2 3 4 5 6 1 1 1 2 1 1 1 1 2 3 1 1 1 2 3 4 1 1 1 1 1 1 1 1 ...

output:

2497507

result:

ok single line: '2497507'

Test #25:

score: 0
Accepted
time: 42ms
memory: 47632kb

input:

619 660
1 1 1 1 2 1 1 1 2 3 6 7 1 2 3 4 1 2 1 2 1 1 1 1 1 1 2 3 4 1 4 5 1 1 1 1 2 1 1 1 2 1 2 3 1 2 3 1 4 1 1 2 1 2 1 1 1 8 9 1 2 1 2 3 4 1 2 1 1 1 1 2 1 1 1 2 3 1 1 2 1 2 3 1 1 2 3 1 2 1 1 2 3 4 1 1 2 3 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 5 1 2 1 1 1 1 1 2 1 1 1 2 3 1 1 2 1 1 1 2 1 2 3 4 5 1 1 1 1 2 1 ...

output:

2575280

result:

ok single line: '2575280'

Test #26:

score: 0
Accepted
time: 21ms
memory: 40424kb

input:

662 317
1 1 1 1 2 3 4 5 1 4 5 1 1 1 1 1 2 3 1 1 1 1 1 2 3 4 5 6 7 1 1 1 1 1 2 3 4 1 1 2 1 1 1 1 2 1 1 2 1 1 1 2 3 4 5 1 1 2 3 1 1 1 1 1 1 2 3 1 1 2 1 1 1 1 1 2 1 1 2 3 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 5 1 2 1 1 1 1 1 2 3 4 1 1 1 1 2 3 4 5 8 9 1 1 1 1 1 1 2 3 4 5 1 1 1 1 2 5 1 1 1 1 2 3 4 5 6 1 2 1 1 ...

output:

1208698

result:

ok single line: '1208698'

Test #27:

score: 0
Accepted
time: 56ms
memory: 56080kb

input:

675 774
1 2 3 4 1 1 2 1 1 1 1 2 3 4 1 1 1 2 1 1 2 3 4 5 1 2 1 2 1 1 1 1 1 1 5 6 7 8 9 10 1 2 3 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 2 3 4 5 6 1 1 1 2 3 1 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 3 4 1 1 1 4 5 1 1 2 1 1 1 1 2 3 4 1 1 2 1 1 2 1 1 7 8 1 2 3 4 1 2 3 1 2 3 4 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1...

output:

5057023

result:

ok single line: '5057023'

Test #28:

score: 0
Accepted
time: 72ms
memory: 69132kb

input:

688 1000
1 1 1 2 1 2 3 4 5 1 1 1 1 1 1 1 2 1 2 1 2 3 1 1 2 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 2 3 1 1 2 3 1 2 1 1 1 4 5 6 7 1 1 1 1 2 5 6 7 1 2 3 4 5 1 1 2 1 2 1 1 2 3 1 1 2 1 1 2 3 4 1 1 1 1 2 3 1 1 4 5 6 7 8 9 10 1 2 1 1 1 1 1 1 1 2 3 4 5 1 1 1 2 3 4 5 1 1 2 5 1 1 1 1 2 1 1 1 1 1 2 ...

output:

2728795

result:

ok single line: '2728795'

Test #29:

score: 0
Accepted
time: 74ms
memory: 68576kb

input:

708 955
1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 2 1 1 2 3 4 5 1 1 1 2 1 2 1 1 1 2 1 1 4 5 6 7 8 1 1 1 1 1 2 7 6 1 1 1 1 1 2 1 1 2 3 1 2 1 2 5 6 1 2 1 1 1 2 1 1 1 2 3 1 2 1 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 3 1 2 1 1 1 1 1 4 1 1 1 1 1 1 2 3 1 1 2 3 4 5 1 1 1 2 3 6 1 2 3 ...

output:

5201757

result:

ok single line: '5201757'

Test #30:

score: 0
Accepted
time: 13ms
memory: 35420kb

input:

724 161
1 1 1 2 3 4 5 6 9 10 1 1 1 1 1 2 3 4 1 2 1 2 1 2 3 1 1 1 1 1 1 1 2 3 1 2 1 1 1 1 1 1 1 1 1 5 1 1 1 1 1 1 2 3 6 7 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 3 4 1 1 1 2 3 8 7 8 9 10 11 12 1 1 1 2 3 4 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 2 1 1 2 5 1 1 2 3 4 1 1 2 3 1 1 1 1 2 3 1 2 1 1 1 1 1 1 1 1 ...

output:

656364

result:

ok single line: '656364'

Test #31:

score: 0
Accepted
time: 24ms
memory: 45180kb

input:

737 386
1 1 2 3 1 1 1 1 1 2 1 2 1 1 1 2 3 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 5 6 1 1 1 2 3 4 1 1 1 1 2 1 1 1 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 2 3 6 1 1 2 3 1 1 1 1 1 1 2 1 1 1 2 1 2 3 4 5 1 1 1 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1 2 3 1 1 2 1 1 1 ...

output:

809816

result:

ok single line: '809816'

Test #32:

score: 0
Accepted
time: 49ms
memory: 55140kb

input:

753 592
1 1 4 1 1 1 1 1 1 1 1 1 1 4 5 6 1 2 1 1 1 1 1 1 1 2 1 1 1 2 3 4 1 2 3 4 5 1 1 2 3 1 2 3 4 5 6 7 14 13 1 2 3 4 5 8 9 10 1 1 2 3 8 1 1 1 1 2 3 1 1 1 4 1 1 1 2 3 1 1 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 1 2 3 4 5 1 1 1 1 1 4 1 1 1 1 2 3 4 1 2 1 2 3 1 1 1 1 1 1 1 2 3 1 1 2 1 1 1 1 2 1 2 1 1 1 1 1 2 1 1...

output:

3580375

result:

ok single line: '3580375'

Test #33:

score: 0
Accepted
time: 90ms
memory: 100076kb

input:

1000 1000
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

482801872

result:

ok single line: '482801872'

Test #34:

score: 0
Accepted
time: 91ms
memory: 87340kb

input:

1000 1000
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

194088777

result:

ok single line: '194088777'