답안 #364273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364273 2021-02-08T17:19:48 Z Mamnoon_Siam Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
162 ms 66028 KB
#include <bits/stdc++.h>
using namespace std;

/* sorry, this is the bare minimum :'( */
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second
#define rep(x,n) for(int x = 0; x < n; ++x)

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 203;
const int inf = 1e9 + 69;

int X[N], L, n, T[N];
int dp[N][N][N][2];

void chkmin(int &x, int y) {
  x = min(x, y);
}

int main(int argc, char const *argv[])
{
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  cin >> n >> L;
  for(int i = 1; i <= n; ++i) {
    cin >> X[i];
  }
  X[0] = 0;
  X[n+1] = L;
  for(int i = 1; i <= n; ++i) {
    cin >> T[i];
  }
  rep(i, N) rep(j, N) rep(k, N) rep(l, 2) dp[i][j][k][l] = inf;

  dp[0][n+1][0][1] = dp[0][n+1][0][0] = 0;
  for(int len = n+1; len > 1; --len) {
    for(int i = 0, j = i+len; j <= n+1; ++i, ++j) {
      for(int k = 0; k <= n; ++k) {
        chkmin(
          dp[i+1][j][k+(dp[i][j][k][0] + X[i+1] - X[i] <= T[i+1])][0],
          dp[i][j][k][0] + X[i+1] - X[i]
        );
        if(X[i+1] - X[i] < 0) debug(i, X[i+1] - X[i]);
        chkmin(
          dp[i][j-1][k+(dp[i][j][k][0] + L-(X[j-1] - X[i]) <= T[j-1])][1],
          dp[i][j][k][0] + L-(X[j-1] - X[i])
        );
        if(L-(X[j-1] - X[i]) < 0) debug(i, j, L-(X[j-1] - X[i]));
        chkmin(
          dp[i+1][j][k+(dp[i][j][k][1] + L-(X[j] - X[i+1]) <= T[i+1])][0],
          dp[i][j][k][1] + L-(X[j] - X[i+1])
        );
        if(L-(X[j] - X[i+1]) < 0) debug(i, j, L-(X[j] - X[i+1]));
        chkmin(
          dp[i][j-1][k+(dp[i][j][k][1] + X[j] - X[j-1] <= T[j-1])][1],
          dp[i][j][k][1] + X[j] - X[j-1]
        );
        if(X[j] - X[j-1] < 0) debug(j, X[j] - X[j-1]);
      }
    }
  }
  int ans = 0;
  for(int i = 0; i <= n+1; ++i) {
    for(int j = i+1; j <= n+1; ++j) {
      for(int k = 0; k <= n; ++k) {
        if(dp[i][j][k][0] < inf or dp[i][j][k][1] < inf) {
          debug(i, j, k, dp[i][j][k][0], dp[i][j][k][1]);
          ans = max(ans, k);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Compilation message

ho_t3.cpp: In function 'int main(int, const char**)':
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
ho_t3.cpp:96:31: note: in expansion of macro 'debug'
   96 |         if(X[i+1] - X[i] < 0) debug(i, X[i+1] - X[i]);
      |                               ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
ho_t3.cpp:101:35: note: in expansion of macro 'debug'
  101 |         if(L-(X[j-1] - X[i]) < 0) debug(i, j, L-(X[j-1] - X[i]));
      |                                   ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
ho_t3.cpp:106:35: note: in expansion of macro 'debug'
  106 |         if(L-(X[j] - X[i+1]) < 0) debug(i, j, L-(X[j] - X[i+1]));
      |                                   ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
ho_t3.cpp:111:31: note: in expansion of macro 'debug'
  111 |         if(X[j] - X[j-1] < 0) debug(j, X[j] - X[j-1]);
      |                               ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 42
      |                    ^~
ho_t3.cpp:120:11: note: in expansion of macro 'debug'
  120 |           debug(i, j, k, dp[i][j][k][0], dp[i][j][k][1]);
      |           ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 65900 KB Output is correct
2 Correct 42 ms 65772 KB Output is correct
3 Correct 44 ms 65796 KB Output is correct
4 Correct 41 ms 65772 KB Output is correct
5 Correct 44 ms 65772 KB Output is correct
6 Correct 44 ms 65804 KB Output is correct
7 Correct 40 ms 65772 KB Output is correct
8 Correct 42 ms 65772 KB Output is correct
9 Correct 42 ms 65772 KB Output is correct
10 Correct 42 ms 65772 KB Output is correct
11 Correct 47 ms 65900 KB Output is correct
12 Correct 42 ms 65772 KB Output is correct
13 Correct 41 ms 65772 KB Output is correct
14 Correct 41 ms 65772 KB Output is correct
15 Correct 41 ms 65772 KB Output is correct
16 Correct 46 ms 65772 KB Output is correct
17 Correct 46 ms 65772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 65900 KB Output is correct
2 Correct 42 ms 65772 KB Output is correct
3 Correct 44 ms 65796 KB Output is correct
4 Correct 41 ms 65772 KB Output is correct
5 Correct 44 ms 65772 KB Output is correct
6 Correct 44 ms 65804 KB Output is correct
7 Correct 40 ms 65772 KB Output is correct
8 Correct 42 ms 65772 KB Output is correct
9 Correct 42 ms 65772 KB Output is correct
10 Correct 42 ms 65772 KB Output is correct
11 Correct 47 ms 65900 KB Output is correct
12 Correct 42 ms 65772 KB Output is correct
13 Correct 41 ms 65772 KB Output is correct
14 Correct 41 ms 65772 KB Output is correct
15 Correct 41 ms 65772 KB Output is correct
16 Correct 46 ms 65772 KB Output is correct
17 Correct 46 ms 65772 KB Output is correct
18 Correct 43 ms 65772 KB Output is correct
19 Correct 42 ms 65792 KB Output is correct
20 Correct 42 ms 65772 KB Output is correct
21 Correct 41 ms 65772 KB Output is correct
22 Correct 45 ms 65772 KB Output is correct
23 Correct 46 ms 65772 KB Output is correct
24 Correct 44 ms 65772 KB Output is correct
25 Correct 42 ms 65772 KB Output is correct
26 Correct 41 ms 65772 KB Output is correct
27 Correct 41 ms 65772 KB Output is correct
28 Correct 47 ms 65772 KB Output is correct
29 Correct 46 ms 65772 KB Output is correct
30 Correct 41 ms 65772 KB Output is correct
31 Correct 44 ms 65772 KB Output is correct
32 Correct 41 ms 65772 KB Output is correct
33 Correct 45 ms 65900 KB Output is correct
34 Correct 46 ms 65772 KB Output is correct
35 Correct 43 ms 65772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 65900 KB Output is correct
2 Correct 42 ms 65772 KB Output is correct
3 Correct 44 ms 65796 KB Output is correct
4 Correct 41 ms 65772 KB Output is correct
5 Correct 44 ms 65772 KB Output is correct
6 Correct 44 ms 65804 KB Output is correct
7 Correct 40 ms 65772 KB Output is correct
8 Correct 42 ms 65772 KB Output is correct
9 Correct 42 ms 65772 KB Output is correct
10 Correct 42 ms 65772 KB Output is correct
11 Correct 47 ms 65900 KB Output is correct
12 Correct 42 ms 65772 KB Output is correct
13 Correct 41 ms 65772 KB Output is correct
14 Correct 41 ms 65772 KB Output is correct
15 Correct 41 ms 65772 KB Output is correct
16 Correct 46 ms 65772 KB Output is correct
17 Correct 46 ms 65772 KB Output is correct
18 Correct 113 ms 65772 KB Output is correct
19 Correct 79 ms 65772 KB Output is correct
20 Correct 57 ms 65772 KB Output is correct
21 Correct 77 ms 65900 KB Output is correct
22 Correct 89 ms 65772 KB Output is correct
23 Correct 53 ms 65900 KB Output is correct
24 Correct 49 ms 65772 KB Output is correct
25 Correct 56 ms 65772 KB Output is correct
26 Correct 45 ms 65772 KB Output is correct
27 Correct 55 ms 65772 KB Output is correct
28 Correct 48 ms 65772 KB Output is correct
29 Correct 52 ms 65900 KB Output is correct
30 Correct 52 ms 65772 KB Output is correct
31 Correct 55 ms 65772 KB Output is correct
32 Correct 50 ms 65772 KB Output is correct
33 Correct 51 ms 65772 KB Output is correct
34 Correct 43 ms 65900 KB Output is correct
35 Correct 52 ms 65772 KB Output is correct
36 Correct 46 ms 65804 KB Output is correct
37 Correct 60 ms 65772 KB Output is correct
38 Correct 48 ms 65772 KB Output is correct
39 Correct 55 ms 65772 KB Output is correct
40 Correct 47 ms 65772 KB Output is correct
41 Correct 162 ms 65772 KB Output is correct
42 Correct 90 ms 65900 KB Output is correct
43 Correct 144 ms 65772 KB Output is correct
44 Correct 99 ms 65900 KB Output is correct
45 Correct 161 ms 66028 KB Output is correct
46 Correct 101 ms 65772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 65900 KB Output is correct
2 Correct 42 ms 65772 KB Output is correct
3 Correct 44 ms 65796 KB Output is correct
4 Correct 41 ms 65772 KB Output is correct
5 Correct 44 ms 65772 KB Output is correct
6 Correct 44 ms 65804 KB Output is correct
7 Correct 40 ms 65772 KB Output is correct
8 Correct 42 ms 65772 KB Output is correct
9 Correct 42 ms 65772 KB Output is correct
10 Correct 42 ms 65772 KB Output is correct
11 Correct 47 ms 65900 KB Output is correct
12 Correct 42 ms 65772 KB Output is correct
13 Correct 41 ms 65772 KB Output is correct
14 Correct 41 ms 65772 KB Output is correct
15 Correct 41 ms 65772 KB Output is correct
16 Correct 46 ms 65772 KB Output is correct
17 Correct 46 ms 65772 KB Output is correct
18 Correct 43 ms 65772 KB Output is correct
19 Correct 42 ms 65792 KB Output is correct
20 Correct 42 ms 65772 KB Output is correct
21 Correct 41 ms 65772 KB Output is correct
22 Correct 45 ms 65772 KB Output is correct
23 Correct 46 ms 65772 KB Output is correct
24 Correct 44 ms 65772 KB Output is correct
25 Correct 42 ms 65772 KB Output is correct
26 Correct 41 ms 65772 KB Output is correct
27 Correct 41 ms 65772 KB Output is correct
28 Correct 47 ms 65772 KB Output is correct
29 Correct 46 ms 65772 KB Output is correct
30 Correct 41 ms 65772 KB Output is correct
31 Correct 44 ms 65772 KB Output is correct
32 Correct 41 ms 65772 KB Output is correct
33 Correct 45 ms 65900 KB Output is correct
34 Correct 46 ms 65772 KB Output is correct
35 Correct 43 ms 65772 KB Output is correct
36 Correct 113 ms 65772 KB Output is correct
37 Correct 79 ms 65772 KB Output is correct
38 Correct 57 ms 65772 KB Output is correct
39 Correct 77 ms 65900 KB Output is correct
40 Correct 89 ms 65772 KB Output is correct
41 Correct 53 ms 65900 KB Output is correct
42 Correct 49 ms 65772 KB Output is correct
43 Correct 56 ms 65772 KB Output is correct
44 Correct 45 ms 65772 KB Output is correct
45 Correct 55 ms 65772 KB Output is correct
46 Correct 48 ms 65772 KB Output is correct
47 Correct 52 ms 65900 KB Output is correct
48 Correct 52 ms 65772 KB Output is correct
49 Correct 55 ms 65772 KB Output is correct
50 Correct 50 ms 65772 KB Output is correct
51 Correct 51 ms 65772 KB Output is correct
52 Correct 43 ms 65900 KB Output is correct
53 Correct 52 ms 65772 KB Output is correct
54 Correct 46 ms 65804 KB Output is correct
55 Correct 60 ms 65772 KB Output is correct
56 Correct 48 ms 65772 KB Output is correct
57 Correct 55 ms 65772 KB Output is correct
58 Correct 47 ms 65772 KB Output is correct
59 Correct 162 ms 65772 KB Output is correct
60 Correct 90 ms 65900 KB Output is correct
61 Correct 144 ms 65772 KB Output is correct
62 Correct 99 ms 65900 KB Output is correct
63 Correct 161 ms 66028 KB Output is correct
64 Correct 101 ms 65772 KB Output is correct
65 Correct 130 ms 65900 KB Output is correct
66 Correct 122 ms 65900 KB Output is correct
67 Correct 118 ms 65772 KB Output is correct
68 Correct 106 ms 65772 KB Output is correct
69 Correct 127 ms 65900 KB Output is correct
70 Correct 128 ms 65772 KB Output is correct
71 Correct 126 ms 65772 KB Output is correct
72 Correct 131 ms 65772 KB Output is correct
73 Correct 114 ms 65900 KB Output is correct
74 Correct 111 ms 65772 KB Output is correct
75 Correct 128 ms 65772 KB Output is correct
76 Correct 136 ms 65772 KB Output is correct
77 Correct 139 ms 65900 KB Output is correct
78 Correct 112 ms 65900 KB Output is correct
79 Correct 110 ms 65772 KB Output is correct
80 Correct 134 ms 65772 KB Output is correct
81 Correct 111 ms 65772 KB Output is correct
82 Correct 130 ms 65772 KB Output is correct
83 Correct 144 ms 65772 KB Output is correct
84 Correct 122 ms 65772 KB Output is correct
85 Correct 141 ms 65772 KB Output is correct
86 Correct 146 ms 65772 KB Output is correct
87 Correct 127 ms 65772 KB Output is correct
88 Correct 146 ms 65772 KB Output is correct
89 Correct 146 ms 65772 KB Output is correct
90 Correct 127 ms 65772 KB Output is correct
91 Correct 152 ms 65772 KB Output is correct
92 Correct 143 ms 65900 KB Output is correct
93 Correct 148 ms 65772 KB Output is correct