QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#440320#6739. TeleportretyrnWA 16ms8436kbC++174.1kb2024-06-13 16:13:172024-06-13 16:13:17

Judging History

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

  • [2024-06-13 16:13:17]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:8436kb
  • [2024-06-13 16:13:17]
  • 提交

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));
    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);
        }
        for (int i = 0; i < k; i ++) {
            y += 1;
            swap(x, y);
            if (x < 0 or y < 0 or x >= n or y >= n) break;
            if (g[x][y] == '*') continue;
            if (f[x][y] < inf) break;
            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: 3528kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 16ms
memory: 8436kb

input:

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

output:

547

result:

wrong answer 1st numbers differ - expected: '540', found: '547'