ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212692 | #3828. B | 15523597526 | 0 | 771ms | 38020kb | C++11 | 1.6kb | 2024-10-20 09:44:01 | 2024-10-20 14:36:21 |
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std ;
ll t , n , m , i , j , maxx , a[2000005] , dp[2000005] , dir[][4] = {{1,0,-1,0},{0,1,0,-1}} ;
vector<ll> ans , tt ;
inline ll dfs(ll x , ll y){
if(dp[x*n+y]){
return dp[x*n+y] ;
}
dp[x*n+y] = 1 ;
for(ll i=0;i<4;i++){
ll tx = x+dir[0][i] , ty = y+dir[1][i] ;
if(tx>=1 && tx<=n && ty>=1 && ty<=m && a[x*n+y]<a[tx*n+ty]){
dp[x*n+y] = max(dp[x*n+y],dfs(tx,ty)+1) ;
maxx = max(maxx,dp[x*n+y]) ;
}
}
return dp[x*n+y] ;
}
inline void dfs2(ll x , ll y , ll step , vector<ll> &v){
if(step==maxx){
if(!ans.size()){
ans = v ;
}else {
for(ll i=0;i<(ll)v.size();i++){
if(ans[i]<v[i]){
return ;
}
if(ans[i]>v[i]){
ans = v ;
return ;
}
}
}
return ;
}
for(ll i=0;i<4;i++){
ll tx = x+dir[0][i] , ty = y+dir[1][i] ;
if(tx>=1 && tx<=n && ty>=1 && ty<=m && dp[x*n+y]==dp[tx*n+ty]+1){
v.push_back(a[tx*n+ty]) ;
dfs2(tx,ty,step+1,v) ;
v.pop_back() ;
}
}
}
int main(){
ios::sync_with_stdio(false) ;
cin.tie(0) ;
cout.tie(0) ;
cin >> t ;
while(t--){
memset(dp,0,sizeof(dp)) ;
maxx = -1 ;
ans.clear() ;
cin >> n >> m ;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin >> a[i*n+j] ;
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
maxx = max(maxx,dfs(i,j)) ;
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(dp[i*n+j]==maxx){
tt.clear() ;
tt.push_back(a[i*n+j]) ;
dfs2(i,j,1,tt) ;
}
}
}
cout << maxx << '\n' ;
for(auto &&k : ans){
cout << k << " " ;
}
cout << '\n' ;
}
return 0 ;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 7ms
memory: 16896kb
input:
10 3 3 0 1 2 3 4 5 6 7 8 3 3 0 1 2 3 4 5 6 8 7 3 3 0 1 2 3 4 5 7 6 8 3 3 0 1 2 3 4 5 7 8 6 3 3 0 1 2...
output:
5 0 1 2 5 8 6 0 1 2 5 7 8 5 0 1 2 5 8 6 0 1 2 5 6 8 5 0 1 2 5 7 7 0 1 2 5 6 7 8 5 0 1 2 6 8 6...
result:
ok 64 numbers
Test #2:
score: -20
Wrong Answer
time: 15ms
memory: 16896kb
input:
10 1 10 1 5 0 8 2 9 6 3 4 7 1 10 2 5 8 0 9 7 3 1 6 4 3 3 0 1 2 5 4 3 6 7 8 1 10 3 4 7 2 5 6 9 0 1 8 ...
output:
3 3 4 7 4 1 3 7 9 9 0 1 2 3 4 5 6 7 8 4 2 5 6 9 3 1 7 9 3 0 1 9 4 0 4 7 9 5 5 6 7 8 9 4 5 7 ...
result:
wrong answer 29th numbers differ - expected: '4', found: '3'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 13ms
memory: 16988kb
input:
10 22 45 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33...
output:
484 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 68 69 70 71 72 73 74 75 76 77 78 79 80 8...
result:
wrong answer 1st numbers differ - expected: '990', found: '484'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 240ms
memory: 38020kb
input:
10 2 100000 143604 106821 145034 44402 118718 156663 77133 28800 81890 12336 191537 118894 103331 75...
output:
9 1398 22656 46151 55141 145384 149540 165970 166461 196691 9 9688 35806 66263 69546 94693 127289 1...
result:
wrong answer 1st numbers differ - expected: '13', found: '9'
Subtask #4:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 253ms
memory: 37184kb
input:
10 1 200000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32...
output:
200000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3...
result:
wrong answer 200002nd numbers differ - expected: '12', found: '11'
Subtask #5:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 243ms
memory: 32084kb
input:
10 145 1379 140324 86968 96426 123781 39754 103720 60835 118904 114639 53717 27146 110309 39232 5608...
output:
13 652 22394 39362 69702 89993 100168 120227 120674 159299 179626 181821 184413 195468 11 2297 1109...
result:
wrong answer 1st numbers differ - expected: '14', found: '13'