제출 #959430

#제출 시각아이디문제언어결과실행 시간메모리
959430Neco_arcLamps (JOI19_lamps)C++17
0 / 100
102 ms166788 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...