답안 #364347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364347 2021-02-09T02:29:38 Z Killer2501 Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
1 ms 876 KB
#include <bits/stdc++.h>
#define pb push_back
#define task "sequence"
#define pll pair<ll, ll>
#define pii pair<vector<ll>, ll>
#define fi first
#define se second

using ll = long long;
const long long mod = 1e9+7;
const ll mod1 = 1e9+1;
const ll N = 205;
const int base = 350;
using ull = unsigned long long;
using namespace std;
string s, ss;
ll n, m, t, k, T, cnt, tong, a[N], c[N], b[N], dp[N][N][N][2];
vector<ll> adj[N], kq;
pll p[N];
int ans;
map<ll, ll> lab, d, bl;
ll findp(ll ui)
{
    if(lab[ui] < 0)return ui;
    ll par = findp(lab[ui]);
    ll dep = d[ui];
    d[ui] = d[ui] ^ t;
    lab[ui] = par;
    t ^= dep;
    //cout << t <<" "<<u<<'\n';
    return par;
}
void hop(ll uj, ll vj, ll ui, ll vi, ll w)
{
    if(lab[uj] > lab[vj])
    {
        swap(uj, vj);
    }
    lab[uj] += lab[vj];
    lab[vj] = uj;
    d[vj] = w ^ d[vi] ^ d[ui];
}
void Min(ll& x, ll y)
{
    if(x > y)x = y;
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        b[i] = m - a[i];
        //cout << b[i] <<" ";
    }
    for(int i = 1; i <= n; i ++)b[i] = m - a[n-i+1];
    //cout << '\n';
    c[0] = c[n+1] = -1;
    for(int i = 1; i <= n; i ++)cin >> c[i];
    for(int i = 0; i <= n; i ++)
        for(int j = 0; j <= n; j ++)
            for(int l = 0; l <= n; l ++)dp[i][j][l][0] = dp[i][j][l][1] = mod;
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    for(int i = 0; i <= n; i ++)
    {
        for(int j = 0; j <= n; j ++)
        {
            for(int l = 0; l <= n; l ++)
            {
                if(dp[i][j][l][0] != mod)
                {
                    ans = max(ans, l);
                        k = dp[i][j][l][0] + a[i+1] - a[i];
                        Min(dp[i+1][j][l+(k<=c[i+1])][0], k);

                        k = dp[i][j][l][0] + b[j+1] + a[i];
                        Min(dp[i][j+1][l+(k<=c[n-j])][1], k);

                }
                if(dp[i][j][l][1] != mod)
                {
                    ans = max(ans, l);

                        k = dp[i][j][l][1] + b[j] + a[i+1];
                        Min(dp[i+1][j][l+(k<=c[i+1])][0], k);

                        k = dp[i][j][l][1] + b[j+1] - b[j];
                        Min(dp[i][j+1][l+(k<=c[n-j])][1], k);


                }
                //cout << i <<" "<<j<<" "<<l<<" "<<dp[i][j][l][0]<<" "<<dp[i][j][l][1] << '\n';
            }
        }
    }
    cout << ans;
}

int main()
{
    if(fopen(task".in", "r")){
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest;
    ntest =  1;
    //cin >> ntest;
    //cout << (1<<30) << '\n';
    while(ntest -- > 0)
    sol();

}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:102:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  102 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:103:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  103 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Incorrect 1 ms 876 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Incorrect 1 ms 876 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Incorrect 1 ms 876 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Incorrect 1 ms 876 KB Output isn't correct
17 Halted 0 ms 0 KB -