답안 #792824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792824 2023-07-25T09:10:47 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
컴파일 오류
0 ms 0 KB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2022;

string a, b;
ll dp[N][N][4];

// 0 don't touched
// 1 turn off all
// 2 turn on  all
// 3 toggle   all

ll change(int pr, int cr) {
    return cr == 3 ? 3 - pr : (cr ? cr : pr);
}

ll recur(int l, int r, int sts) {
    int &ans = dp[l][r][sts];
    if(ans != -1) {
        return ans;
    }
    if(l + 1 == r) {
        if(sts == 0) {
            return ans = (a[l] != b[l]);
        } 
        if(sts == 1) {
            return ans = ('0' != b[l]);
        } 
        if(sts == 2) {
            return ans = ('1' != b[l]);
        }
        return ans = (a[l] == b[l]);
    }
    ans = r - l;
    for(int m = l + 1; m < r; ++ m) {
        int ansl = recur(l, m, sts);
        for(int nwsts = 1; nwsts < 4; ++ nwsts) {
            ansl = min(ansl, recur(l, m, change(sts, nwsts)) + 1);
        }
        int ansr = recur(m, r, sts);
        for(int nwsts = 1; nwsts < 4; ++ nwsts) {
            ansr = min(ansr, recur(m, r, change(sts, nwsts)) + 1);
        }
        ans = min(ans, ansl + ansr);
    }
    return ans;
}

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    memset(dp, -1, sizeof dp);
    
    int n;
    cin >> n >> a >> b;
    bool ok = a[0] == '0';
    int ans = a[0] != b[0];
    for(int i = 1; i < a.size(); ++ i) {
        ok &= a[i] == '0';
        ans += (b[i] == '1' && b[i - 1] == '0'); 
    }
    if(ok) {
        cout << ans;
        return 0;
    }
    cout << min( {
    recur(0, n, 0),
    recur(0, n, 1) + 1,
    recur(0, n, 2) + 1,
    recur(0, n, 3) + 1} );
}

Compilation message

travel.cpp: In function 'll recur(int, int, int)':
travel.cpp:27:28: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   27 |     int &ans = dp[l][r][sts];
      |                ~~~~~~~~~~~~^
travel.cpp:47:65: error: no matching function for call to 'min(int&, ll)'
   47 |             ansl = min(ansl, recur(l, m, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
travel.cpp:47:65: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   47 |             ansl = min(ansl, recur(l, m, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
travel.cpp:47:65: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   47 |             ansl = min(ansl, recur(l, m, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
travel.cpp:47:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |             ansl = min(ansl, recur(l, m, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
travel.cpp:47:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |             ansl = min(ansl, recur(l, m, change(sts, nwsts)) + 1);
      |                                                                 ^
travel.cpp:51:65: error: no matching function for call to 'min(int&, ll)'
   51 |             ansr = min(ansr, recur(m, r, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
travel.cpp:51:65: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   51 |             ansr = min(ansr, recur(m, r, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
travel.cpp:51:65: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   51 |             ansr = min(ansr, recur(m, r, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
travel.cpp:51:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   51 |             ansr = min(ansr, recur(m, r, change(sts, nwsts)) + 1);
      |                                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from travel.cpp:5:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
travel.cpp:51:65: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   51 |             ansr = min(ansr, recur(m, r, change(sts, nwsts)) + 1);
      |                                                                 ^
travel.cpp: At global scope:
travel.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main() {
      | ^~~~
travel.cpp: In function 'int main()':
travel.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i = 1; i < a.size(); ++ i) {
      |                    ~~^~~~~~~~~~