Submission #1082451

# Submission time Handle Problem Language Result Execution time Memory
1082451 2024-08-31T11:12:45 Z phong Lamps (JOI19_lamps) C++17
0 / 100
10 ms 7984 KB
#include<bits/stdc++.h>

#define ll long long
const int nmax = 2e3 + 5, N = 1e5;
const ll oo = 1e18 + 1, base = 311;
const int lg = 15, M = 4;
const ll mod = 998244353, mod2 = 1e9 + 5277;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n;
string a, b;
int dp[nmax][65 + 1][2];
int deg[nmax];
struct node{
    int f[M];
}one[nmax];
int sz = 0, g[nmax], stu[nmax];
int F[2][100];
void add(vector<int> &v){
    ++sz;
    g[sz] = v.size();
    if(v.size() >= 1) one[sz].f[0] = v[0];
    if(v.size() >= 2) one[sz].f[1] = v[1];
    if(v.size() >= 3) one[sz].f[2] = v[2];
    if(v.size() >= 4) one[sz].f[3] = v[3];
    int res = 0;
    for(int i = 0; i < M; ++i){
        res = res * 10 + one[sz].f[i];
    }
    stu[sz] = res;
    deg[res] = sz;
    for(int x = 0; x < 2; ++x){
        int id = x;
        for(int i = 0; i < M; ++i){
            if(one[sz].f[i] == 1) id = 0;
            if(one[sz].f[i] == 2) id = 1;
            if(one[sz].f[i] == 3) id ^= 1;
            if(one[sz].f[i] == 4) id^= 1;
        }
        F[x][sz] = id;
    }
}
int val[nmax];
vector<int> v;
void update(int m){
    v.clear();
    for(int i = 1; i <= m; ++i) v.push_back(val[i]);
    do{
        add(v);
    }
    while(next_permutation(v.begin(), v.end()));
}
void calc(int i){
    for(int j = val[i - 1] + 1; j <= M; ++j){
        val[i] = j;
        update(i);
        if(i < M) calc(i + 1);

    }
}
vector<pii> adj[100], gg[100];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n;
    cin >> a;
    cin >> b;
    a = ' ' + a;
    b = ' ' + b;
    memset(dp, 0x3f, sizeof dp);
    dp[0][0][0] = 0;
    calc(1);

    for(int i = 0; i <= sz; ++i){
        for(int j = 0; j <= sz; ++j){
            if(g[i] + g[j] <= M){
                bool ok = 1;
                for(int x = 0; x < M; ++x){
                    if(!one[i].f[x]) break;
                    for(int y = 0; y < M; ++y){
                        if(!one[j].f[y])break;
                        if(one[i].f[x] == one[j].f[y]) ok = 0;
                    }
                }
                if(ok){
                    int res = 0;
                    for(int x = 0; x < M; ++x){
                        if(!one[i].f[x]) break;
                        res = res * 10 + one[i].f[x];
                    }
                    for(int x = 0; x < M; ++x){
                        if(!one[j].f[x]) break;
                        res = res * 10 + one[j].f[x];
                    }
                    int x = M - g[i] - g[j];
                    while(x > 0){
                        res *= 10;
                        --x;
                    }
                    adj[i].push_back({deg[res], g[j]});
                }
            }
        }
        int res = 0;
        gg[i].push_back({0, 0});
        for(int x = 0; x < M; ++x){
            if(!one[i].f[x]) break;
            res = res * 10 + one[i].f[x];
                int cur = res;
                for(int j = x + 1; j < M; ++j) cur *= 10;
                gg[i].push_back({deg[cur], 0});

        }
    }
//    cout << sz;
    F[0][0] =0, F[1][0] = 1;
    for(int i = 0; i < n;++i){
        int x;
        if(i == 0) x = 0;
        else x = b[i] - '0';
        for(int msk = sz; msk >= 0; --msk){
            for(auto [new_msk, cost] : adj[msk]){
                dp[i][new_msk][x] = min(dp[i][new_msk][x], dp[i][msk][x] + cost);
            }
        }
        for(int msk = sz; msk >= 0; --msk){
            for(auto [new_msk, cost] : gg[msk]){
                int y = a[i + 1] - '0';
                int id = F[y][new_msk];
                dp[i + 1][new_msk][id] = min(dp[i + 1][new_msk][id], dp[i][msk][x] + cost);
            }
        }
    }
    int ans = 1e9;
    for(int msk = 0; msk <= sz; ++msk) ans = min(ans, dp[n][msk][b[n]-'0']);
    cout << ans;
}
/*
10
1111001110
1010100111

111001110
010100111

000100
000100000
010100111

*/

Compilation message

lamp.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1500 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 1 ms 1496 KB Output is correct
22 Correct 1 ms 1372 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Incorrect 1 ms 1372 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1500 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 1 ms 1496 KB Output is correct
22 Correct 1 ms 1372 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Incorrect 1 ms 1372 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Runtime error 10 ms 7984 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1500 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct
21 Correct 1 ms 1496 KB Output is correct
22 Correct 1 ms 1372 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Incorrect 1 ms 1372 KB Output isn't correct
27 Halted 0 ms 0 KB -