2 solutions

  • 0
    @ 2025-1-31 14:16:22

    #include<bits/stdc++.h> using namespace std; const int N=200; int n,m,s,a[N][N],cnt=0; int dx[4]={0,-1,0,1}; int dy[4]={-1,0,1,0}; struct point{ int x; int y; int nums; }; queueq; void bfs(int x,int y) { point temp; temp.x=x; temp.y=y; temp.nums=a[x][y]; q.push(temp); while(!q.empty()) { temp=q.front(); cnt=max(cnt,temp.nums); for(int i=0;i<4;i++){ int nx=temp.x+dx[i]; int ny=temp.y+dy[i]; if(a[nx][ny]>a[temp.x][temp.y]&&nx>=0&&nx<n&&ny>=0&&ny<m){ q.push({nx,ny,temp.nums+a[nx][ny]}); } } q.pop(); } } int main() { int i,j; cin>>n>>m>>s; for(i=0;i<n;i++){ for(j=0;j<m;j++){ s=(s*345)%19997; a[i][j]=s%10+1; } } for(i=0;i<n;i++){ for(j=0;j<m;j++){ bfs(i,j); } } cout<<cnt; return 0; }

    Information

    ID
    718
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    4
    Tags
    # Submissions
    110
    Accepted
    48
    Uploaded By