QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611573#8236. Snake MovexixuWA 1037ms54960kbC++113.3kb2024-10-04 21:32:552024-10-04 21:32:55

Judging History

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

  • [2024-10-04 21:32:55]
  • 评测
  • 测评结果:WA
  • 用时:1037ms
  • 内存:54960kb
  • [2024-10-04 21:32:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int short
// #define int long long

typedef long long ll;
typedef pair<int , int> PII;
typedef pair<int , pair<int , int>> PIII;


const int M = 2e7 + 80000 , N = 2e7 + 1000 , inf = 0x3f3f3f3f;

int n , m , k;
int aa[N];
char s[N];
int dist[N];
int d[4][2] = {{0 , 1} , {0 , -1} , {1 , 0} , {-1 , 0}};
int ss[N];

int nu(int x , int y)
{
    return (x - 1) * m + y;
}

int xx(int x)
{
    return (x + m - 1) / m;
}

int yy(int x)
{
    if(x % m) return x % m;
    return m;
}

struct no
{
    int op , len;
    bool st;
};




void bfs()
{
    for(int i = 0; i <= n * m + 10; i ++) dist[i] = inf;

    dist[ss[1]] = 0;

    priority_queue<PIII , vector<PIII> , greater<PIII>> heap;
    heap.push({0 , {ss[1] , k}});



    while(heap.size())
    {
        auto t = heap.top();
        heap.pop();

        int op = t.second.first , len = t.second.second;
        int dis = t.first;
        // cout << '\n';
        // cout << xx(op) << ' ' << yy(op) << "  : " << '\n';
        

        for(int i = 0; i < 4; i ++)
        {
            int dx = xx(op) + d[i][0] , dy = yy(op) + d[i][1];
            int j = nu(dx , dy);
            
            if(dx < 1 || dy < 1 || dx > n || dy > m || s[j] == '#') continue ;
            // cout << dx << ' ' << dy << '\n';
            if(!aa[j] || len < aa[j])
            {
                if(dist[j] > dis + 1)
                {
                    dist[j] = dis + 1;
                    heap.push({dist[j] , {j , len}});
                }
            }
            else
            {
                int nn = len - aa[j];
                if(nn <= dis)
                {
                    if(dist[j] > dis + 1)
                    {
                        dist[j] = dis + 1;
                        heap.push({dist[j] , {j , len}});
                    }
                }
                else
                {
                    int xxx = nn - dis;
                    if(dist[j] > dis + xxx + 1)
                    {
                        dist[j] = dis + xxx + 1;
                        heap.push({dist[j] , {j , len - xxx}});
                    }
                    // else
                    // {
                    //     heap.push({dis + xxx + 1 , {j , len - xxx}});
                    // }
                }
            }
            // cout << dist[j] << '\n';
        }
    }

}



void solve()
{
    cin >> n >> m >> k;
    
    for(int i = 1; i <= k; i ++)
    {
        int x , y;
        cin >> x >> y;
        aa[nu(x , y)] = i;
        ss[i] = nu(x , y);
    }

    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            cin >> s[nu(i , j)];
        }
    }

    bfs();

    unsigned long long su = 0;

    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            if(dist[nu(i , j)] != inf) 
            {
                su += 1LL * dist[nu(i , j)] * dist[nu(i , j)];
            }
        }
    }

    cout << su << '\n';
}



signed main()
{
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);

    int _ = 1;
    // cin >> _;
    while(_ --)
    {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9924kb

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

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

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 970ms
memory: 50952kb

input:

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

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 879ms
memory: 50736kb

input:

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

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 68ms
memory: 52748kb

input:

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

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 73ms
memory: 54952kb

input:

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

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 999ms
memory: 52780kb

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: 902ms
memory: 54824kb

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: 71ms
memory: 54960kb

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: 69ms
memory: 52700kb

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: 1037ms
memory: 52848kb

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:

41693681934961

result:

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