QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#440364#6739. TeleportretyrnWA 362ms83732kbC++175.3kb2024-06-13 16:55:452024-06-13 16:55:46

Judging History

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

  • [2024-06-13 16:55:46]
  • 评测
  • 测评结果:WA
  • 用时:362ms
  • 内存:83732kb
  • [2024-06-13 16:55:45]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <cassert>
#include <cctype>
#include <ciso646>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#endif

#define FAST ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15)
#define Tsolve() int T; cin >> T; while (T --) solve()
#define endl '\n'
#define em(x) (x.empty())
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define Fill(x,a) memset(x,a,sizeof(x))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define pbk push_back
#define mpr make_pair
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define fi first
#define se second
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
//-----------------------precompiler--------------------
using ll = long long;
using i64 = long long;
using pii = std::pair<int,int>;
using VI = std::vector<int>;
using namespace std;
template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
//-----------------------debug-----------------------
#ifndef ONLINE_JUDGE
#include "D:/OneDrive-Personal/OneDrive/my-acm-template/my_header/debug.h"
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) {}
#endif
//-----------------------constant-----------------------
const int maxn = 2e5+10;
const int inf = 0x3f3f3f3f;
const ll inf2 = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int mod = 1e9+7;
const int mod2 = 998244353;
ll gcd(ll a,ll b) { return b?gcd(b, a%b):a;}
//-----------------------variable-----------------------
int n, k;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
//-----------------------function-----------------------

void solve() {
    cin >> n >> k;
    vector<string> g(n);
    cin >> g;
    
    vector<vector<int>> f(n, vector<int>(n, inf));
    vector<vector<int>> trans(n, vector<int>(n, 0)); // 记录一个位置是否经过传送
    f[0][0] = 0;
    queue<pii> q;
    q.emplace(0, 0);
    
    while (!em(q)) {
        int x = q.front().fi, y = q.front().se;
        int val = f[x][y];
        if (x == n -1 and y == n - 1) break;
        q.pop();
        for (int i = 0; i < 4; i ++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 or nx >= n or ny < 0 or ny >= n) continue;
            if (g[nx][ny] == '*' or f[nx][ny] < inf) continue;
            f[nx][ny] = val + 1;
            q.emplace(nx, ny);
        }
        
        if (!trans[x][y]) {
            for (int i = 0; i < k; i ++) {
                y += 1;
                swap(x, y);
                if (x >= n or y >= n) break;
                if (trans[x][y]) break;
                trans[x][y] = 1;
                if (g[x][y] == '*' or f[x][y] < inf) continue;
                f[x][y] = val + 1;
                q.emplace(x, y);
            }
        }
        else {
            // 二分找到这条线路上第一个没有跳到的位置
            int l = 1, r = k;
            while (l < r) {
                auto mid = (l + r + 1) >> 1;
                int nx = x + (mid / 2), ny = y + (mid / 2);
                if (mid & 1) {
                    ny += 1;
                    swap(nx, ny);
                }
                
                if (nx >= n or ny >= n or !trans[nx][ny]) r = mid - 1;
                else l = mid;
            }
            x += l / 2;
            y += l / 2;
            if (l & 1) {
                y += 1;
                swap(x, y);
            }
            for (int i = l; i < k; i ++) {
                y += 1;
                swap(x, y);
                if (x >= n or y >= n) break;
                trans[x][y] = 1;
                if (g[x][y] == '*' or f[x][y] < inf) continue;
                f[x][y] = val + 1;
                q.emplace(x, y);
            }
        }
            
    }
    
    cout << (f[n-1][n-1] == inf ? -1 : f[n-1][n-1]) << endl;
}
int main() {
    FAST;
    // Tsolve();
    solve();

    return 0;
}

// (x,y) (y+1,x) (x+1,y+1) (y+2,x+1) (x+2,y+2)

詳細信息

Test #1:

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

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 26ms
memory: 11940kb

input:

961 4
...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....

output:

540

result:

ok 1 number(s): "540"

Test #4:

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

input:

975 434
.*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 9ms
memory: 11888kb

input:

966 19
..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....

output:

104

result:

ok 1 number(s): "104"

Test #6:

score: 0
Accepted
time: 5ms
memory: 12108kb

input:

973 199
..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 6ms
memory: 12196kb

input:

984 95
.....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....

output:

21

result:

ok 1 number(s): "21"

Test #8:

score: -100
Wrong Answer
time: 362ms
memory: 83732kb

input:

2996 2
..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...

output:

3435

result:

wrong answer 1st numbers differ - expected: '3354', found: '3435'