제출 #1194585

#제출 시각아이디문제언어결과실행 시간메모리
1194585Zbyszek99Homework (CEOI22_homework)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<long long>
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

struct dp
{
    pll dp[3];
};

string s;
int close[1000'001];
int n;

dp calc(int l, int r, int type)
{
    vector<dp> dps;
    rep2(i,l,r)
    {
        if(s[i] == '?')
        {
            dp new_dp;
            new_dp.dp[0] = {1,1};
            new_dp.dp[1] = {0,0};
            new_dp.dp[2] = {0,0};
            dps.pb(new_dp);
        }
        if(s[i] == 'm')
        {
            if(s[i+1] == 'a')
            {
                dps.pb(calc(i+4,close[i+3]-1,1));
            }
            else 
            {
                dps.pb(calc(i+4,close[i+3]-1,0));
            }
            i = close[i+3];
        }
    }
    dp ans;
    vi max_sum[3];
    vi min_sum[3];    
    if(type == 0)
    {
        rep(d,3)
        {
            ans.dp[d] = {1e9,-1e9};
            max_sum[d].pb(0);
            min_sum[d].pb(0);
            forall(it,dps)
            {
                if(d == 0)
                {
                    max_sum[d].pb(max_sum[d].back() + max(it.dp[0].ss,it.dp[2].ss));
                    min_sum[d].pb(min_sum[d].back() + min(it.dp[0].ff,it.dp[2].ff));
                }
                if(d == 1)
                {
                    max_sum[d].pb(max_sum[d].back() + it.dp[2].ss);
                    min_sum[d].pb(min_sum[d].back() + it.dp[2].ff);    
                }
                if(d == 2)
                {
                    max_sum[d].pb(max_sum[d].back() + it.dp[2].ss);
                    min_sum[d].pb(min_sum[d].back() + it.dp[2].ff);
                }
            }
        }
    }
    else
    {
        rep(d,3)
        {
            ans.dp[d] = {1e9,-1e9};
            max_sum[d].pb(0);
            min_sum[d].pb(0);
            forall(it,dps)
            {
                if(d == 0)
                {
                    
                    max_sum[d].pb(max_sum[d].back() + it.dp[0].ss);
                    min_sum[d].pb(min_sum[d].back() + it.dp[0].ff);
                }
                if(d == 1)
                {
                    max_sum[d].pb(max_sum[d].back() + it.dp[0].ss);
                    min_sum[d].pb(min_sum[d].back() + it.dp[0].ff);    
                }
                if(d == 2)
                {
                    max_sum[d].pb(max_sum[d].back() + max(it.dp[0].ss,it.dp[2].ss));
                    min_sum[d].pb(min_sum[d].back() + min(it.dp[0].ff,it.dp[2].ff));
                }
            }
        }
    }
    rep(i,siz(dps))
    {
        rep(d,3)
        {
            ans.dp[d].ff = min(ans.dp[d].ff,dps[i].dp[d].ff + min_sum[d][i] + min_sum[d].back() - min_sum[d][i+1]);
            ans.dp[d].ss = max(ans.dp[d].ss,dps[i].dp[d].ss + max_sum[d][i] + max_sum[d].back() - max_sum[d][i+1]);
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //random();
    cin >> s;
    stack<int> st;
    n = siz(s);
    rep(i,n)
    {
        if(s[i] == '(')
        {
            st.push(i);
        }
        if(s[i] == ')')
        {
            close[st.top()] = i;
            st.pop();
        }
    }
    dp d = (s[1] == 'a' ? calc(4,n-2,1) : calc(4,n-2,0));
    cout << d.dp[1].ss - d.dp[1].ff+1 << "\n";
}

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

Main.cpp:31:19: error: 'int close [1000001]' redeclared as different kind of entity
   31 | int close[1000'001];
      |                   ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/11/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:43,
                 from Main.cpp:1:
/usr/include/unistd.h:358:12: note: previous declaration 'int close(int)'
  358 | extern int close (int __fd);
      |            ^~~~~
Main.cpp: In function 'dp calc(int, int, int)':
Main.cpp:51:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   51 |                 dps.pb(calc(i+4,close[i+3]-1,1));
      |                                          ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
Main.cpp:51:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   51 |                 dps.pb(calc(i+4,close[i+3]-1,1));
      |                                 ~~~~~~~~~~^~
Main.cpp:51:43: error: invalid conversion from 'int (*)(int)' to 'int' [-fpermissive]
   51 |                 dps.pb(calc(i+4,close[i+3]-1,1));
      |                                 ~~~~~~~~~~^~
      |                                           |
      |                                           int (*)(int)
Main.cpp:34:20: note:   initializing argument 2 of 'dp calc(int, int, int)'
   34 | dp calc(int l, int r, int type)
      |                ~~~~^
Main.cpp:55:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   55 |                 dps.pb(calc(i+4,close[i+3]-1,0));
      |                                          ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
Main.cpp:55:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   55 |                 dps.pb(calc(i+4,close[i+3]-1,0));
      |                                 ~~~~~~~~~~^~
Main.cpp:55:43: error: invalid conversion from 'int (*)(int)' to 'int' [-fpermissive]
   55 |                 dps.pb(calc(i+4,close[i+3]-1,0));
      |                                 ~~~~~~~~~~^~
      |                                           |
      |                                           int (*)(int)
Main.cpp:34:20: note:   initializing argument 2 of 'dp calc(int, int, int)'
   34 | dp calc(int l, int r, int type)
      |                ~~~~^
Main.cpp:57:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |             i = close[i+3];
      |                          ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
Main.cpp:57:26: error: invalid conversion from 'int (*)(int)' to 'int' [-fpermissive]
   57 |             i = close[i+3];
      |                 ~~~~~~~~~^
      |                          |
      |                          int (*)(int)
Main.cpp: In function 'int main()':
Main.cpp:144:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  144 |             close[st.top()] = i;
      |                           ^
Main.cpp:144:29: error: assignment of read-only location '*(close, (close + ((sizetype)st.std::stack<int>::top())))'
  144 |             close[st.top()] = i;
      |             ~~~~~~~~~~~~~~~~^~~