QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368293#8236. Snake MovewdwWA 1188ms224452kbC++202.7kb2024-03-26 23:07:002024-03-26 23:07:01

Judging History

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

  • [2024-03-26 23:07:01]
  • 评测
  • 测评结果:WA
  • 用时:1188ms
  • 内存:224452kb
  • [2024-03-26 23:07:00]
  • 提交

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;
    inline bool operator<(const node &x)const {
        return cnt>x.cnt;
    }
};
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;
        }
    }
    priority_queue<node>q;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>pic[i][j];
            dis[i][j]=1e9;
            if(idx[i][j]){
                dis[i][j]=max(k-2+idx[i][j]-1,1ll*0);
                q.push({ dis[i][j],i,j,2});
            }
        }
    }
    dis[x][y]=0;
    q.push({0,x,y,k});
    while(!q.empty()){
        auto y=q.top();
        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{
                    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++){
            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: 3548kb

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: 3776kb

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: 3832kb

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 1174ms
memory: 217228kb

input:

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

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 929ms
memory: 217160kb

input:

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

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 96ms
memory: 224052kb

input:

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

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 96ms
memory: 216672kb

input:

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

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1077ms
memory: 217020kb

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: 934ms
memory: 224452kb

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: 0
Accepted
time: 99ms
memory: 216624kb

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:

40571

result:

ok single line: '40571'

Test #11:

score: 0
Accepted
time: 84ms
memory: 216604kb

input:

2900 3000 10
2447 135
2447 136
2447 137
2447 138
2447 139
2447 140
2448 140
2448 139
2449 139
2449 138
.#.##.##..#.###########.#####.###....#####.########..##..#.####.##.##.####.####..#.#####.##.#.#.###.##.#.##.####..##.#.####..###..###...##...##.#####.#####.#...#####.####..##.##.#.#..#..####.##..##...

output:

2705

result:

ok single line: '2705'

Test #12:

score: -100
Wrong Answer
time: 1188ms
memory: 224356kb

input:

3000 3000 100
2573 1917
2572 1917
2572 1916
2573 1916
2574 1916
2574 1915
2573 1915
2572 1915
2571 1915
2571 1914
2570 1914
2570 1915
2569 1915
2569 1916
2568 1916
2568 1917
2569 1917
2570 1917
2570 1916
2571 1916
2571 1917
2571 1918
2570 1918
2569 1918
2569 1919
2570 1919
2571 1919
2571 1920
2572 1...

output:

41693681936725

result:

wrong answer 1st lines differ - expected: '41693682087973', found: '41693681936725'