QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#523895#4434. Lemurssroid_03#AC ✓1685ms61612kbC++144.3kb2024-08-18 21:50:062024-08-18 21:50:07

Judging History

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

  • [2024-08-18 21:50:07]
  • 评测
  • 测评结果:AC
  • 用时:1685ms
  • 内存:61612kb
  • [2024-08-18 21:50:06]
  • 提交

answer

// by Siddhid Saha (2112010)


#include <bits/stdc++.h>
#include <queue>
using namespace std;

#define INF 1e18
#define endl "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define PI atan(1)*4
#define set_bits __builtin_popcountllO
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define rvsort(a) sort(all(a),greater<int>())
#define read(a,n) for(int i = 0 ; i < n ; i ++){ cin >> a[i];}
#define printv(a) for(auto it: a){cout << it << " ";} cout << endl;
#define ms(arr, v) memset(arr, v, sizeof(arr))

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#ifndef ONLINE_JUDGE
#include "/Users/templates/debug.h"
#else
#define dbg(x...)
#endif
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
void google(int t) {cout << "Case #" << t << ": ";}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
ll uid(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);} 
/*--------------------------------------------------------------------------------------------------------------------------*/
//const int mod = 1e9 + 7;
//const int mod = 998244353; 


vector<array<ll,2>> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};


void solve()
{
    ll n, m , k; cin >> n >> m  >> k;
    vector<vector<char>> vc(n, vector<char>(m, '.'));
    vector<vll> vis(n, vll(m, 0));
    queue<array<ll,3>> q;
    for(int i = 0 ; i < n ; i ++){
        for(int j =0 ; j < m ;j ++){
            cin >> vc[i][j];
            if(vc[i][j] == '.'){
                q.push({i, j, 0});
            }
        }
    }
    vector<vector<char>> nvc = vc;
    while(!q.empty()){
        auto [x, y, d] = q.front();
        q.pop();
        if(d > k || vis[x][y]) continue;
        vis[x][y] = 1;
        nvc[x][y] = '.';
        auto isValid = [&](int x, int y)->bool{
            return (x >= 0 && x < n && y >= 0  && y < m);
        };
        for(auto [dx, dy]: dir){
            if(isValid(x+dx, y+dy) && !vis[x+dx][y+dy]){
                q.push({x+dx, y+dy, d+1});
            }
        }
    }
    queue<array<ll,3>> nq;
    for(int i = 0 ; i < n ; i ++){
        for(int j = 0; j  < m ; j ++){
            if(nvc[i][j] == 'x'){
                nq.push({i, j, 0});
            }
        }
    }
    vis.assign(n, vll(m, 0));
    while(!nq.empty()){
        auto [x, y, d] = nq.front();
        nq.pop();
        if(d > k || vis[x][y]) continue;
        vis[x][y] = 1;
        nvc[x][y] = 'x';
        auto isValid = [&](int x, int y)->bool{
            return (x >= 0 && x < n && y >= 0  && y < m);
        };
        for(auto [dx, dy]: dir){
            if(isValid(x+dx, y+dy) && !vis[x+dx][y+dy]){
                nq.push({x+dx, y+dy, d+1});
            }
        }
    }
    for(int i = 0 ; i < n ; i ++){
        for(int j = 0 ; j < m ; j ++){
            if(nvc[i][j] != vc[i][j]){
                cout << "NIE" << endl;
                return;
            }
        }
    }
    cout << "TAK" << endl;

}

int main() {

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);


ll t = 1;
cin >> t;
for(int i = 1 ; i <= t ; i++){
//google(i);
solve();
}
return 0;
}









详细

Test #1:

score: 100
Accepted
time: 19ms
memory: 3876kb

input:

4000
1 1 1
.
1 1 1
x
1 1 1000
.
1 1 1000
x
1 1000 4
..........................................xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

TAK
TAK
TAK
TAK
TAK
NIE
NIE
TAK
NIE
TAK
NIE
NIE
TAK
TAK
NIE
TAK
TAK
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
TAK
NIE
NIE
TAK
TAK
TAK
NIE
NIE
NIE
TAK
TAK
NIE
NIE
TAK
NIE
NIE
NIE
TAK
NIE
NIE
NIE
TAK
NIE
NIE
NIE
NIE
TAK
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
TAK
NIE
NIE
NIE
TAK
TAK
...

result:

ok 4000 lines

Test #2:

score: 0
Accepted
time: 1685ms
memory: 61612kb

input:

36
1000 1000 2
....xxxx..............xxxxxx..........xx..xxxx......xxxxxxxxxxx.........xxxxxxxxxx...xxxxxx....xxxxxx.......xxxxxx....xxxxxx......................................xx.............xxxxxxxxx......xxxxxxx................xxxxxx..xxxxxx....xxxxxx..............xxxxxxxxxxxxxxxxxxxxxxxxxxxx...x...

output:

TAK
NIE
NIE
TAK
TAK
NIE
TAK
NIE
NIE
TAK
TAK
NIE
NIE
NIE
NIE
TAK
NIE
TAK
TAK
TAK
TAK
NIE
TAK
NIE
NIE
TAK
NIE
TAK
NIE
NIE
NIE
TAK
TAK
NIE
NIE
NIE

result:

ok 36 lines

Test #3:

score: 0
Accepted
time: 1577ms
memory: 61032kb

input:

41
1000 1000 999
.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

NIE
TAK
TAK
NIE
TAK
TAK
TAK
NIE
TAK
NIE
TAK
TAK
TAK
NIE
TAK
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
TAK
NIE
TAK
NIE
NIE
NIE
NIE
TAK
TAK
NIE
NIE
NIE
TAK
NIE
NIE
NIE

result:

ok 41 lines

Extra Test:

score: 0
Extra Test Passed