QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808340#9802. Light Up the GridMiniLong#WA 275ms4332kbC++203.8kb2024-12-10 20:01:402024-12-10 20:01:42

Judging History

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

  • [2024-12-10 20:01:42]
  • 评测
  • 测评结果:WA
  • 用时:275ms
  • 内存:4332kb
  • [2024-12-10 20:01:40]
  • 提交

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 = (1 << 16) + 5;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll T, n = 16, m, tot, a[5][5], c[5];
int code(){return (a[0][0] << 3) | (a[0][1] << 2) | (a[1][0] << 1) | a[1][1];}
int vis[20];
ll f[N];
bool update(){
    int st = 0;
    _rep(i, 0, 15) if(vis[i]) st |= (1 << i);
    if(f[st] > tot) return f[st] = tot, 1;
    return 0;
}
void dfs(bool flag = 0){
    if(vis[code()]) return;
    if(flag) vis[code()] = 1;
    if(!update()) return vis[code()] = 0, void();
    _rep(i, 0, 1) _rep(j, 0, 1){
        a[i][j] ^= 1, tot += c[0];
        dfs(1);
        a[i][j] ^= 1, tot -= c[0];
    }
    _rep(i, 0, 1){
        _rep(j, 0, 1) a[i][j] ^= 1; tot += c[1];
        dfs(1);
        _rep(j, 0, 1) a[i][j] ^= 1; tot -= c[1];
    }
    _rep(i, 0, 1){
        _rep(j, 0, 1) a[j][i] ^= 1; tot += c[2];
        dfs(1);
        _rep(j, 0, 1) a[j][i] ^= 1; tot -= c[2];
    }
    _rep(i, 0, 1) _rep(j, 0, 1) a[i][j] ^= 1; tot += c[3];
    dfs(1);
    _rep(i, 0, 1) _rep(j, 0, 1) a[i][j] ^= 1; tot -= c[3];
    if(flag) vis[code()] = 0;
}
int main(){
    mst(f, inf);
    read(T, c[0], c[1], c[2], c[3]);
    dfs();
    _rep(i, 0, 15) _req(j, (1 << 16) - 1, 1) if(j >> i & 1) f[j ^ (1 << i)] = min(f[j ^ (1 << i)], f[j]);
    while(T--){
        read(m);
        int st = 0;
        _rep(t, 1, m){
            _rep(i, 0, 1){
                char ch[5]; scanf("%s", ch);
                _rep(j, 0, 1) a[i][j] = ch[j] - '0', a[i][j] ^= 1;
            }
            st |= 1 << code();
        }
        writeln(f[st]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 275ms
memory: 4332kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

score: 0
Accepted
time: 20ms
memory: 4324kb

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2

result:

ok 2 number(s): "5 2"

Test #3:

score: 0
Accepted
time: 20ms
memory: 4320kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 117ms
memory: 4268kb

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:

34
32
36
37
40
36
42
38
40
41
36
44
34
38
38
32
29
40
40
40
38
40
44
38
29
38
38
38
34
34
33
42
34
36
41
40
46
34
38
34
29
36
40
40
42
36
39
38
38
38
41
29
40
42
38
42
44
41
41
34
42
39
37
33
34
38
38
37
42
40
34
36
28
34
34
38
36
39
38
38
36
40
34
34
36
34
42
40
38
38
40
40
37
40
38
29
38
40
38
34
...

result:

wrong answer 4th numbers differ - expected: '36', found: '37'