제출 #1332534

#제출 시각아이디문제언어결과실행 시간메모리
1332534adscodingLamps (JOI19_lamps)C++20
100 / 100
80 ms55228 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __print_one(const char *&s, const T &x)
{
    while (*s == ' ') ++s;
    const char *p = s;
    int bal = 0;
    while (*s)
    {
        if (*s == '(') ++bal;
        else if (*s == ')') --bal;
        else if (*s == ',' && bal == 0) break;
        ++s;
    }
    cerr.write(p, s - p) << " = " << x;
    if (*s == ',')
    {
        ++s;
        cerr << "  ,  ";
    }
}

template<typename... Args>
void debug(const char *s, Args... args)
{
    cerr << "[  ";
    int dummy[] = { 0 , ( __print_one(s, args) , 0 )... };
    (void)dummy;
    cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, X b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template<class X>
bool minimize(X &a, X b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

// --------------------------------------------------------------------------------------------

int n, state[1000005], fState[1000005];
ll dp[1000005][3][2];

// --------------------------------------------------------------------------------------------


bool check(int i, int j, int k)
{
    int val = (j == 2 ? state[i] : j) ^ k;
    return val == fState[i];
}


void solve()
{
    cin >> n;
    FOR(i, 1, n)
    {
        char ch; cin >> ch;
        state[i] = ch - '0';
    }
    FOR(i, 1, n)
    {
        char ch; cin >> ch;
        fState[i] = ch - '0';
    }

    FOR(i, 0, n)
        FOR(j, 0, 2)
            FOR(k, 0, 1)
                dp[i][j][k] = 1e18;

    dp[0][2][0] = 0;
    FOR(i, 0, n - 1)
    {
        FOR(j, 0, 2)
            FOR(k, 0, 1)
            {
                if (dp[i][j][k] == ll(1e18)) continue;
                FOR(newj, 0, 2)
                    FOR(newk, 0, 1)
                    {
                        if (check(i + 1, newj, newk))
                            minimize(dp[i + 1][newj][newk], dp[i][j][k] + (newj != 2 && newj != j) + (newk != k && newk == 1));
                    }
            }
    }

    ll res = 1e18;
    FOR(j, 0, 2)
        FOR(k, 0, 1)
            res = min(res, dp[n][j][k]);

    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define TASK "TEST"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    solve();
    return 0;
}

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

lamp.cpp: In function 'int main()':
lamp.cpp:135:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:136:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |         freopen(TASK".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...