Submission #959430

# Submission time Handle Problem Language Result Execution time Memory
959430 2024-04-08T08:02:22 Z Neco_arc Lamps (JOI19_lamps) C++17
0 / 100
102 ms 166788 KB
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define Neco "lamps"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e3 + 7

using namespace std;

const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;

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

ll GetRandom(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r)(rng);
}

int n;
string a, b;
int dp[maxn][maxn][5];

char _get(char x, int type) {
    if(type == 0) return x;
    if(type == 1) return '0';
    if(type == 2) return '1';
    if(type == 3) return x == '0' ? '1' : '0';
}

int turn(int x, int t) {
    if(x == 0) return t;
    if(t == 0) return x;
    if(t == 1) return min(2, x);
    if(t == 2) return x == 2 ? 2 : 1;
    if(t == 3) return x == 3 ? 0 : x;
}

int calc(int l, int r, int t)
{
    if(l == r) return _get(a[l], t) == b[l] ? 0 : 1e9;
    if(dp[l][r][t] >= 0) return dp[l][r][t];

    int res = 1e9;

    fi(i, l, r - 1) {
        fi(x, 0, 3) fi(y, 0, 3)
        {
            int w, u = turn(x, t), v = turn(y, t);
            if(x != y) w = (u != t) + (v != t);
            else w = (u != t);

            res = min(res, calc(l, i, u) + calc(i + 1, r, v) + w);
        }
    }

    return dp[l][r][t] = res;
}

void solve()
{

    cin >> n >> a >> b;
    a = ' ' + a, b = ' ' + b;
    memset(dp, -1, sizeof dp);

    int res = 1e9;

    fi(i, 0, 3) res = min(res, calc(1, n, i) + (i > 0));


    cout << res;
//    cout << calc(1, 1, 0);//get(a[1], 0);


}


int main()
{

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

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message

lamp.cpp: In function 'char _get(char, int)':
lamp.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
   37 | }
      | ^
lamp.cpp: In function 'int turn(int, int)':
lamp.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
   45 | }
      | ^
lamp.cpp: In function 'int main()':
lamp.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 79128 KB Output is correct
2 Correct 27 ms 79192 KB Output is correct
3 Correct 28 ms 79188 KB Output is correct
4 Correct 27 ms 79200 KB Output is correct
5 Correct 27 ms 79240 KB Output is correct
6 Correct 31 ms 79156 KB Output is correct
7 Correct 26 ms 79024 KB Output is correct
8 Correct 27 ms 79192 KB Output is correct
9 Correct 27 ms 79048 KB Output is correct
10 Correct 27 ms 79124 KB Output is correct
11 Correct 27 ms 79212 KB Output is correct
12 Correct 27 ms 79184 KB Output is correct
13 Correct 27 ms 79192 KB Output is correct
14 Correct 27 ms 79184 KB Output is correct
15 Correct 27 ms 79192 KB Output is correct
16 Correct 27 ms 79196 KB Output is correct
17 Correct 27 ms 79192 KB Output is correct
18 Correct 27 ms 79196 KB Output is correct
19 Correct 30 ms 79040 KB Output is correct
20 Correct 28 ms 79176 KB Output is correct
21 Correct 26 ms 79172 KB Output is correct
22 Correct 31 ms 79060 KB Output is correct
23 Correct 31 ms 79188 KB Output is correct
24 Correct 27 ms 79184 KB Output is correct
25 Correct 30 ms 79184 KB Output is correct
26 Incorrect 29 ms 79196 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 79128 KB Output is correct
2 Correct 27 ms 79192 KB Output is correct
3 Correct 28 ms 79188 KB Output is correct
4 Correct 27 ms 79200 KB Output is correct
5 Correct 27 ms 79240 KB Output is correct
6 Correct 31 ms 79156 KB Output is correct
7 Correct 26 ms 79024 KB Output is correct
8 Correct 27 ms 79192 KB Output is correct
9 Correct 27 ms 79048 KB Output is correct
10 Correct 27 ms 79124 KB Output is correct
11 Correct 27 ms 79212 KB Output is correct
12 Correct 27 ms 79184 KB Output is correct
13 Correct 27 ms 79192 KB Output is correct
14 Correct 27 ms 79184 KB Output is correct
15 Correct 27 ms 79192 KB Output is correct
16 Correct 27 ms 79196 KB Output is correct
17 Correct 27 ms 79192 KB Output is correct
18 Correct 27 ms 79196 KB Output is correct
19 Correct 30 ms 79040 KB Output is correct
20 Correct 28 ms 79176 KB Output is correct
21 Correct 26 ms 79172 KB Output is correct
22 Correct 31 ms 79060 KB Output is correct
23 Correct 31 ms 79188 KB Output is correct
24 Correct 27 ms 79184 KB Output is correct
25 Correct 30 ms 79184 KB Output is correct
26 Incorrect 29 ms 79196 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 79200 KB Output is correct
2 Correct 28 ms 79192 KB Output is correct
3 Correct 27 ms 79184 KB Output is correct
4 Correct 28 ms 79236 KB Output is correct
5 Correct 27 ms 79188 KB Output is correct
6 Correct 26 ms 79236 KB Output is correct
7 Runtime error 102 ms 166788 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 79128 KB Output is correct
2 Correct 27 ms 79192 KB Output is correct
3 Correct 28 ms 79188 KB Output is correct
4 Correct 27 ms 79200 KB Output is correct
5 Correct 27 ms 79240 KB Output is correct
6 Correct 31 ms 79156 KB Output is correct
7 Correct 26 ms 79024 KB Output is correct
8 Correct 27 ms 79192 KB Output is correct
9 Correct 27 ms 79048 KB Output is correct
10 Correct 27 ms 79124 KB Output is correct
11 Correct 27 ms 79212 KB Output is correct
12 Correct 27 ms 79184 KB Output is correct
13 Correct 27 ms 79192 KB Output is correct
14 Correct 27 ms 79184 KB Output is correct
15 Correct 27 ms 79192 KB Output is correct
16 Correct 27 ms 79196 KB Output is correct
17 Correct 27 ms 79192 KB Output is correct
18 Correct 27 ms 79196 KB Output is correct
19 Correct 30 ms 79040 KB Output is correct
20 Correct 28 ms 79176 KB Output is correct
21 Correct 26 ms 79172 KB Output is correct
22 Correct 31 ms 79060 KB Output is correct
23 Correct 31 ms 79188 KB Output is correct
24 Correct 27 ms 79184 KB Output is correct
25 Correct 30 ms 79184 KB Output is correct
26 Incorrect 29 ms 79196 KB Output isn't correct
27 Halted 0 ms 0 KB -