QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621984#8742. 黑白MiniLongAC ✓41ms8684kbC++173.3kb2024-10-08 19:08:202024-10-08 19:08:22

Judging History

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

  • [2024-10-08 19:08:22]
  • 评测
  • 测评结果:AC
  • 用时:41ms
  • 内存:8684kb
  • [2024-10-08 19:08:20]
  • 提交

answer

#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
    #ifdef ONLINE_JUDGE
    char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
    #define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
    #else
    #define get() getchar()
    #endif
    template<typename T> inline void read(T &t){
        T x = 0, f = 1;
        char c = getchar();
        while(!isdigit(c)){
            if(c == '-') f = -f;
            c = getchar();
        }
        while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
        t = x * f;
    }
    template<typename T, typename ... Args> inline void read(T &t, Args&... args){
        read(t);
        read(args...);
    }
    template<typename T> void write(T t){
        if(t < 0) putchar('-'), t = -t;
        if(t >= 10) write(t / 10);
        putchar(t % 10 + '0');
    }
    template<typename T, typename ... Args> void write(T t, Args... args){
        write(t), putchar(' '), write(args...);
    }
    template<typename T> void writeln(T t){
        write(t);
        puts("");
    }
    template<typename T> void writes(T t){
        write(t), putchar(' ');
    }
    #undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
    const ll mod = 998244353;
    ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
    void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
    void add(ll &x, ll y){x = (x + y) % mod;}
    void mul(ll &x, ll y){x = x * y % mod;}
    ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
    ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
    ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1005, M = 1e6 + 5;
int n, m, fa[M];
int code(int x, int y){return (x - 1) * m + y;}
int find(int x){return fa[x] == x ? x : fa[x] = find(fa[x]);}
void merge(int x, int y){int fx = find(x), fy = find(y); if(fx != fy) fa[fx] = fy;}
char s[N][N];
int main(){
    multitest(){
        read(n, m);
        _rep(i, 1, n) _rep(j, 1, m) fa[code(i, j)] = code(i, j);
        _rep(i, 1, n){
            scanf("%s", s[i] + 1);
            _rep(j, 1, m){
                if(j > 1 && s[i][j] == 'W' && s[i][j - 1] == 'W') merge(code(i, j), code(i, j - 1));
                if(i > 1 && s[i][j] == 'W' && s[i - 1][j] == 'W') merge(code(i - 1, j), code(i, j));
            }
        }
        if(find(1) != find(n * m)) puts("J");
        else{
            int cur = n + m - 1, cnt = 0;
            _rep(i, 1, n) _rep(j, 1, m) cnt += s[i][j] == 'W';
            cnt -= cur;
            if(cnt & 1) puts("I");
            else puts("J");
        }
        _rep(i, 1, n) _rep(j, 1, m) fa[code(i, j)] = 0;
    }    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 41ms
memory: 8684kb

input:

100
2 6
WWBBWW
WWWWWB
3 8
WWWBBBBB
WWWBWWWB
BBWWWBWW
5 2
WB
BB
BB
BW
BB
6 4
WWBW
WBWB
WWWW
WWWB
BBWW
BWBW
2 3
WWW
WBW
124 125
BWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWBWWWWWWWWBWWWWWWWWWWWBBBBWWWWWWWWWWWWWWWWWBWWWWWWWWWBWWWWWWWWWWBWWWWWWWWBBWWWWWWWWWWWWWWWWWWB
WWWWWWWBWWBWWWWWWWWWWWBWWBWWBWWWWBWWWWWWWWWBWBWB...

output:

J
J
J
I
I
J
I
I
I
J
I
J
J
J
J
J
I
I
I
I
J
J
I
I
I
J
J
I
J
J
J
J
I
J
J
J
J
J
J
I
J
J
I
I
I
J
J
I
J
J
J
I
J
I
J
J
J
J
I
I
J
J
J
I
J
J
I
J
I
I
J
J
J
I
J
I
I
J
J
I
J
J
J
J
J
I
J
J
J
I
I
J
J
I
I
J
J
J
J
I

result:

ok 100 lines