ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212828 | #3828. B | seven_07 | 0 | 0ms | 1264kb | C++ | 1.5kb | 2024-10-20 11:55:10 | 2024-10-20 14:39:28 |
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct P{
int x;
int y;
int s;
string an;
};
string str(int x){
string ans = "";
while(x){
ans=char(x%10+'0')+ans;
x/=10;
}
return ans;
}
bool check(string a,string b,int s){
int sz1=0,sz2=0;
int x=0,y=0;
int cnt = 0;
while(cnt<s){
while(a[x]!=' ') x++,(sz1=a[x]-'0')+sz1*10;
while(a[y]!=' ') y++,(sz2=b[y]-'0')+sz2*10;
x++,y++;
if(sz1>sz2) return false;
if(sz1<sz2) return true;
sz1=0,sz2=0;
cnt++;
}
return false;
}
int d[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int v[2005][2005];
int a[2005][2005];
int n,m;
int tx,ty;
ll cnt=1;
string ans="0";
void BFS(int x,int y){
queue<P> Q;
Q.push({x,y,1,"0"});
while(Q.size()){
P f = Q.front();
P q;
Q.pop();
int flag = 0;
for(int i = 0;i < 4;i++){
q.x = f.x+d[i][1];
q.y = f.y+d[i][0];
q.an = f.an;
if(q.x>=1&&q.x<=n&&q.y>=1&&q.y<=m&&a[q.x][q.y]>a[f.x][f.y]){
q.an=f.an+' '+str(a[q.x][q.y]);
flag=1;
Q.push({q.x,q.y,f.x+1,q.an});
}
}
if(!flag){
if(f.s>cnt||f.s==cnt&&check(q.an,ans,cnt)){
cnt=f.s;
ans=q.an;
}
// else if(f.s==cnt&&check(q.an,ans,cnt)){
// cnt=f.s;
// ans=q.an;
// }
}
}
return;
}
int main(){
int t; cin >> t;
while(t--){
cnt=0,ans="0";
cin >> n >> m;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
cin >> a[i][j];
if(a[i][j]==0) tx=i,ty=j;
}
}
BFS(tx,ty);
cout << cnt << endl << ans << endl;
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1264kb
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:
4 0 3 6 7 8 4 0 3 6 8 4 0 3 4 6 8 4 0 3 7 8 4 0 3 4 6 7 4 0 3 4 7 8 4 0 3 5 7 8 4 0 3 5 8 4 0 3 4 5 ...
result:
wrong answer 1st numbers differ - expected: '5', found: '4'
Subtask #2:
score: 0
Time Limit Exceeded
Test #3:
score: 0
Time Limit Exceeded
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:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded
input:
10 2 100000 143604 106821 145034 44402 118718 156663 77133 28800 81890 12336 191537 118894 103331 75...
output:
2 0 168733 2 0 103433 169527 1 0 2 0 158121 2 0 34497 47197
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #6:
score: 0
Time Limit Exceeded
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:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #7:
score: 0
Time Limit Exceeded
input:
10 145 1379 140324 86968 96426 123781 39754 103720 60835 118904 114639 53717 27146 110309 39232 5608...
output:
89 0 36399 178628 186719 44 0 34096 195605 199440 39 0 59169 134675 100 0 20348 56549 181634 9 0 189...