QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368239#8236. Snake MovewdwWA 577ms224556kbC++203.8kb2024-03-26 22:15:062024-03-26 22:15:08

Judging History

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

  • [2024-03-26 22:15:08]
  • 评测
  • 测评结果:WA
  • 用时:577ms
  • 内存:224556kb
  • [2024-03-26 22:15:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 5e5 + 5;
const int mod = 1e9+7;
const double eps =0.00001;
#define int long long
#define ull unsigned long long
#define endl '\n'
using i64 = int64_t;
int ksm(int a,int b){
    int ans=1;
    while(b){
        if(b%2)ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
struct node{
    int cnt=0,x,y,k;
};
vector<vector<char>>pic;
vector<vector<int>>idx,dis,vis;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void solve() {
    int n,m,k;
    cin>>n>>m>>k;
    pic=vector<vector<char>>(n+5,vector<char>(m+5));
    vis=dis=idx=vector<vector<int>>(n+5,vector<int>(m+5));
    int x,y;
    for(int i=1,x1,y1;i<=k;i++){
         if(i==1){
             cin>>x>>y;
             idx[x][y]=i;
         }else{
             cin>>x1>>y1;
             idx[x1][y1]=i;
         }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>pic[i][j];
            dis[i][j]=1e9;
        }
    }
    dis[x][y]=0;
    queue<node>q;
    q.push({0,x,y,k});
    while(!q.empty()){
        auto y=q.front();
        q.pop();
        if(vis[y.x][y.y])continue;
        vis[y.x][y.y]=1;
        for(int i=0;i<4;i++){
            int x1=y.x+dx[i],y1=y.y+dy[i];
            if(x1<1||x1>n||y1<1||y1>m||pic[x1][y1]=='#')continue;
            if(idx[x1][y1]){
                if(y.k-idx[x1][y1]-y.cnt<=0){
                    if(dis[x1][y1]>dis[y.x][y.y]+1){
                        dis[x1][y1]=dis[y.x][y.y]+1;
                        q.push({dis[x1][y1],x1,y1,y.k});
                    }
                }else{
                    continue;

                    int p=y.k-idx[x1][y1]-y.cnt;
                    if(dis[x1][y1]>dis[y.x][y.y]+1+p){
                        dis[x1][y1]=dis[y.x][y.y]+1+p;
                        q.push({dis[x1][y1],x1,y1,y.k-p});
                    }
                }
            }else{
                if(dis[x1][y1]>dis[y.x][y.y]+1){
                    dis[x1][y1]=dis[y.x][y.y]+1;
                    q.push({dis[x1][y1],x1,y1,y.k});
                }
            }
        }
    }
    q.push({0,x,y,k});
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
         vis[i][j]=0;
        }
    }
    while(!q.empty()){
        auto y=q.front();
        q.pop();
        if(vis[y.x][y.y])continue;
        vis[y.x][y.y]=1;
        for(int i=0;i<4;i++){
            int x1=y.x+dx[i],y1=y.y+dy[i];
            if(x1<1||x1>n||y1<1||y1>m||pic[x1][y1]=='#')continue;
            if(idx[x1][y1]){
                if(y.k-idx[x1][y1]-y.cnt<=0){
                    if(dis[x1][y1]>dis[y.x][y.y]+1){
                        dis[x1][y1]=dis[y.x][y.y]+1;
                        q.push({dis[x1][y1],x1,y1,y.k});
                    }
                   // q.push({dis[x1][y1],x1,y1,y.k});
                }else{
                    int p=y.k-idx[x1][y1]-y.cnt;
                    if(dis[x1][y1]>dis[y.x][y.y]+1+p){
                        dis[x1][y1]=dis[y.x][y.y]+1+p;
                        q.push({dis[x1][y1],x1,y1,y.k-p});
                    }
                }
            }else{
                if(dis[x1][y1]>dis[y.x][y.y]+1){
                    dis[x1][y1]=dis[y.x][y.y]+1;
                    q.push({dis[x1][y1],x1,y1,y.k});
                }
            }
        }
    }
   ull  ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
         //   cout<<dis[i][j]<<" ";
          if(dis[i][j]==1e9)continue;
          ans+=(ull)(dis[i][j]*dis[i][j]);
        }
    }
    cout<<ans<<endl;
}
signed main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cout<<fixed<<setprecision(11);
    int T = 1;
    //  cin >> T;
    while (T--) solve();
    return 0;
}

詳細信息

Test #1:

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

input:

4 5 5
3 5
3 4
3 3
3 2
4 2
.....
.....
.....
.....

output:

293

result:

ok single line: '293'

Test #2:

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

input:

2 2 4
1 1
1 2
2 2
2 1
..
..

output:

14

result:

ok single line: '14'

Test #3:

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

input:

5 5 3
1 2
1 1
2 1
.....
.###.
.#.#.
.###.
.....

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 551ms
memory: 217220kb

input:

3000 2900 1
1882 526
........................................................................................................#................................................................................................................................................................#................

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 556ms
memory: 217444kb

input:

2900 3000 1
1333 1773
.....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 99ms
memory: 224016kb

input:

3000 3000 1
2755 225
##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 88ms
memory: 216756kb

input:

3000 2900 1
878 738
#.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 530ms
memory: 217216kb

input:

2900 3000 10
2883 1758
2883 1759
2883 1760
2883 1761
2883 1762
2884 1762
2884 1763
2883 1763
2882 1763
2882 1764
........................................................#............................#........................................................................................................

output:

49803365625286

result:

ok single line: '49803365625286'

Test #9:

score: 0
Accepted
time: 577ms
memory: 224556kb

input:

3000 3000 10
2015 1932
2015 1931
2015 1930
2015 1929
2016 1929
2017 1929
2018 1929
2018 1928
2018 1927
2017 1927
#...#...#..#.........#.......#####....#...###..#..###..###....##.....#..#..#...#.....##...##.#..#..##.###.........##.....#....#..##.##.#.#.##.#.#.#.....#....##.##.#..##....#....#...#.#......

output:

22509095749285

result:

ok single line: '22509095749285'

Test #10:

score: -100
Wrong Answer
time: 93ms
memory: 216664kb

input:

3000 2900 10
326 1781
325 1781
325 1782
325 1783
325 1784
324 1784
324 1783
323 1783
323 1782
324 1782
##.#....#.###.######..#.#.....##.#.##..####.####.##..#..#.###.#####....##.#.##.#..###..##.###.##.#####.###..##.#..##..##.#..##.#.#.##...##..#.##.##........#..#..###.##.###.####.#..########.##.....#...

output:

41915

result:

wrong answer 1st lines differ - expected: '40571', found: '41915'