답안 #20450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20450 2017-02-11T15:25:39 Z mistake(#47, aloshipda) Can polan into space? (OJUZ11_space) C++14
100 / 100
163 ms 39456 KB
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <complex>

#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define pf(a) push_font((a))
#define rb() pop_back()
#define rf() pop_front()
#define sz(a) ((int)a.size())

using namespace std;
 
typedef long long lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;
typedef pair<lld, int> pli;
typedef pair<int, lld> pil;
typedef vector<vector<int>> Matrix;
typedef vector<vector<int>> Adj;
typedef vector<int> Row;
typedef complex<double> Complex;
typedef vector<Complex> Vcomplex;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const lld LINF = 1e18;
const double FINF = 1e15;
const double EPS = 1e-9;
const double PI = 2.0 * acos(0.0);

lld D[200005][2][2];
int pl[200005][2][2];
int pr[200005][2][2];
int n;
int a[200005][3];
int vis[200005];
vector<int> adj[200005];
vector<int> ord;
inline void asmax(lld& x, lld y) {
  if (x < y) x = y;
}

inline void asmax(int i1, int a1, int b1, int i2, int a2, int b2) {
  if (D[i1][a1][b1] < D[i2][a2][b2] + a[i1][a1 + b1]) {
    D[i1][a1][b1] = D[i2][a2][b2] + a[i1][a1 + b1];
    pl[i1][a1][b1] = a2;
    pr[i1][a1][b1] = b2;
  }
}

void dfs(int cur) {
  vis[cur] = true;
  for (int nxt : adj[cur]) {
    if (!vis[nxt]) dfs(nxt);
  }
  ord.pb(cur);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        D[i][j][k] = -LINF;
      }
    }
  }
  D[0][0][1] = 0;
  for (int i = 0; i < n; ++i) {
    asmax(i+1, 1, 0, i, 1, 0);
    asmax(i+1, 1, 1, i, 1, 0);
    asmax(i+1, 1, 0, i, 0, 0);
    asmax(i+1, 1, 1, i, 0, 0);
    asmax(i+1, 0, 0, i, 0, 1);
    asmax(i+1, 0, 1, i, 0, 1);
    asmax(i+1, 0, 0, i, 1, 1);
    asmax(i+1, 0, 1, i, 1, 1);
    /*
    asmax(D[i+1][1][0], D[i][1][0] + b[i+1]); //i -> i+1
    asmax(D[i+1][1][1], D[i][1][0] + c[i+1]); 
    asmax(D[i+1][1][0], D[i][0][0] + b[i+1]);
    asmax(D[i+1][1][1], D[i][0][0] + c[i+1]);
    asmax(D[i+1][0][0], D[i][0][1] + a[i+1]); //i+1 -> i
    asmax(D[i+1][0][1], D[i][0][1] + b[i+1]); 
    asmax(D[i+1][0][0], D[i][1][1] + a[i+1]);
    asmax(D[i+1][0][1], D[i][1][1] + b[i+1]);
    */
  }
  lld ans = max(D[n][1][0], D[n][0][0]);
  int cur = n;
  int l = (ans == D[n][1][0]), r = 0;
  while (cur > 1) {
    if (l == 1) {
      adj[cur-1].pb(cur);
    } else {
      adj[cur].pb(cur-1);
    }
    int nl = pl[cur][l][r];
    int nr = pr[cur][l][r];
    l = nl;
    r = nr;
    --cur;
  }
  for (int i = 1; i <= n; ++i) if (!vis[i]) dfs(i);
  printf("%lld\n", ans);
  for (int i = n-1; i >= 0; --i) {
    printf("%d ", ord[i]);
  }
}

Compilation message

space.cpp: In function 'int main()':
space.cpp:72:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
space.cpp:75:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &a[i][j]);
                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 22332 KB Output is correct
2 Correct 0 ms 22332 KB Output is correct
3 Correct 0 ms 22332 KB Output is correct
4 Correct 0 ms 22332 KB Output is correct
5 Correct 3 ms 22332 KB Output is correct
6 Correct 0 ms 22332 KB Output is correct
7 Correct 3 ms 22332 KB Output is correct
8 Correct 0 ms 22332 KB Output is correct
9 Correct 0 ms 22332 KB Output is correct
10 Correct 0 ms 22332 KB Output is correct
11 Correct 3 ms 22332 KB Output is correct
12 Correct 0 ms 22332 KB Output is correct
13 Correct 0 ms 22332 KB Output is correct
14 Correct 0 ms 22332 KB Output is correct
15 Correct 0 ms 22332 KB Output is correct
16 Correct 3 ms 22332 KB Output is correct
17 Correct 3 ms 22332 KB Output is correct
18 Correct 0 ms 22332 KB Output is correct
19 Correct 3 ms 22332 KB Output is correct
20 Correct 0 ms 22332 KB Output is correct
21 Correct 0 ms 22332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 22332 KB Output is correct
2 Correct 0 ms 22332 KB Output is correct
3 Correct 0 ms 22332 KB Output is correct
4 Correct 0 ms 22332 KB Output is correct
5 Correct 3 ms 22332 KB Output is correct
6 Correct 0 ms 22332 KB Output is correct
7 Correct 3 ms 22332 KB Output is correct
8 Correct 0 ms 22332 KB Output is correct
9 Correct 0 ms 22332 KB Output is correct
10 Correct 0 ms 22332 KB Output is correct
11 Correct 3 ms 22332 KB Output is correct
12 Correct 0 ms 22332 KB Output is correct
13 Correct 0 ms 22332 KB Output is correct
14 Correct 0 ms 22332 KB Output is correct
15 Correct 0 ms 22332 KB Output is correct
16 Correct 3 ms 22332 KB Output is correct
17 Correct 3 ms 22332 KB Output is correct
18 Correct 0 ms 22332 KB Output is correct
19 Correct 3 ms 22332 KB Output is correct
20 Correct 0 ms 22332 KB Output is correct
21 Correct 0 ms 22332 KB Output is correct
22 Correct 0 ms 22332 KB Output is correct
23 Correct 3 ms 22332 KB Output is correct
24 Correct 0 ms 22332 KB Output is correct
25 Correct 0 ms 22332 KB Output is correct
26 Correct 3 ms 22332 KB Output is correct
27 Correct 0 ms 22332 KB Output is correct
28 Correct 0 ms 22332 KB Output is correct
29 Correct 0 ms 22332 KB Output is correct
30 Correct 0 ms 22332 KB Output is correct
31 Correct 3 ms 22332 KB Output is correct
32 Correct 3 ms 22332 KB Output is correct
33 Correct 0 ms 22332 KB Output is correct
34 Correct 0 ms 22332 KB Output is correct
35 Correct 0 ms 22332 KB Output is correct
36 Correct 3 ms 22332 KB Output is correct
37 Correct 0 ms 22332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 22332 KB Output is correct
2 Correct 0 ms 22332 KB Output is correct
3 Correct 0 ms 22332 KB Output is correct
4 Correct 0 ms 22332 KB Output is correct
5 Correct 3 ms 22332 KB Output is correct
6 Correct 0 ms 22332 KB Output is correct
7 Correct 3 ms 22332 KB Output is correct
8 Correct 0 ms 22332 KB Output is correct
9 Correct 0 ms 22332 KB Output is correct
10 Correct 0 ms 22332 KB Output is correct
11 Correct 3 ms 22332 KB Output is correct
12 Correct 0 ms 22332 KB Output is correct
13 Correct 0 ms 22332 KB Output is correct
14 Correct 0 ms 22332 KB Output is correct
15 Correct 0 ms 22332 KB Output is correct
16 Correct 3 ms 22332 KB Output is correct
17 Correct 3 ms 22332 KB Output is correct
18 Correct 0 ms 22332 KB Output is correct
19 Correct 3 ms 22332 KB Output is correct
20 Correct 0 ms 22332 KB Output is correct
21 Correct 0 ms 22332 KB Output is correct
22 Correct 0 ms 22332 KB Output is correct
23 Correct 3 ms 22332 KB Output is correct
24 Correct 0 ms 22332 KB Output is correct
25 Correct 0 ms 22332 KB Output is correct
26 Correct 3 ms 22332 KB Output is correct
27 Correct 0 ms 22332 KB Output is correct
28 Correct 0 ms 22332 KB Output is correct
29 Correct 0 ms 22332 KB Output is correct
30 Correct 0 ms 22332 KB Output is correct
31 Correct 3 ms 22332 KB Output is correct
32 Correct 3 ms 22332 KB Output is correct
33 Correct 0 ms 22332 KB Output is correct
34 Correct 0 ms 22332 KB Output is correct
35 Correct 0 ms 22332 KB Output is correct
36 Correct 3 ms 22332 KB Output is correct
37 Correct 0 ms 22332 KB Output is correct
38 Correct 0 ms 22332 KB Output is correct
39 Correct 3 ms 22332 KB Output is correct
40 Correct 0 ms 22332 KB Output is correct
41 Correct 0 ms 22332 KB Output is correct
42 Correct 3 ms 22332 KB Output is correct
43 Correct 0 ms 22332 KB Output is correct
44 Correct 0 ms 22332 KB Output is correct
45 Correct 0 ms 22332 KB Output is correct
46 Correct 3 ms 22332 KB Output is correct
47 Correct 0 ms 22332 KB Output is correct
48 Correct 0 ms 22332 KB Output is correct
49 Correct 3 ms 22332 KB Output is correct
50 Correct 3 ms 22332 KB Output is correct
51 Correct 0 ms 22332 KB Output is correct
52 Correct 3 ms 22332 KB Output is correct
53 Correct 3 ms 22332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 22332 KB Output is correct
2 Correct 0 ms 22332 KB Output is correct
3 Correct 0 ms 22332 KB Output is correct
4 Correct 0 ms 22332 KB Output is correct
5 Correct 3 ms 22332 KB Output is correct
6 Correct 0 ms 22332 KB Output is correct
7 Correct 3 ms 22332 KB Output is correct
8 Correct 0 ms 22332 KB Output is correct
9 Correct 0 ms 22332 KB Output is correct
10 Correct 0 ms 22332 KB Output is correct
11 Correct 3 ms 22332 KB Output is correct
12 Correct 0 ms 22332 KB Output is correct
13 Correct 0 ms 22332 KB Output is correct
14 Correct 0 ms 22332 KB Output is correct
15 Correct 0 ms 22332 KB Output is correct
16 Correct 3 ms 22332 KB Output is correct
17 Correct 3 ms 22332 KB Output is correct
18 Correct 0 ms 22332 KB Output is correct
19 Correct 3 ms 22332 KB Output is correct
20 Correct 0 ms 22332 KB Output is correct
21 Correct 0 ms 22332 KB Output is correct
22 Correct 0 ms 22332 KB Output is correct
23 Correct 3 ms 22332 KB Output is correct
24 Correct 0 ms 22332 KB Output is correct
25 Correct 0 ms 22332 KB Output is correct
26 Correct 3 ms 22332 KB Output is correct
27 Correct 0 ms 22332 KB Output is correct
28 Correct 0 ms 22332 KB Output is correct
29 Correct 0 ms 22332 KB Output is correct
30 Correct 0 ms 22332 KB Output is correct
31 Correct 3 ms 22332 KB Output is correct
32 Correct 3 ms 22332 KB Output is correct
33 Correct 0 ms 22332 KB Output is correct
34 Correct 0 ms 22332 KB Output is correct
35 Correct 0 ms 22332 KB Output is correct
36 Correct 3 ms 22332 KB Output is correct
37 Correct 0 ms 22332 KB Output is correct
38 Correct 0 ms 22332 KB Output is correct
39 Correct 3 ms 22332 KB Output is correct
40 Correct 0 ms 22332 KB Output is correct
41 Correct 0 ms 22332 KB Output is correct
42 Correct 3 ms 22332 KB Output is correct
43 Correct 0 ms 22332 KB Output is correct
44 Correct 0 ms 22332 KB Output is correct
45 Correct 0 ms 22332 KB Output is correct
46 Correct 3 ms 22332 KB Output is correct
47 Correct 0 ms 22332 KB Output is correct
48 Correct 0 ms 22332 KB Output is correct
49 Correct 3 ms 22332 KB Output is correct
50 Correct 3 ms 22332 KB Output is correct
51 Correct 0 ms 22332 KB Output is correct
52 Correct 3 ms 22332 KB Output is correct
53 Correct 3 ms 22332 KB Output is correct
54 Correct 0 ms 22332 KB Output is correct
55 Correct 6 ms 22760 KB Output is correct
56 Correct 9 ms 23072 KB Output is correct
57 Correct 6 ms 22760 KB Output is correct
58 Correct 6 ms 22760 KB Output is correct
59 Correct 6 ms 22760 KB Output is correct
60 Correct 13 ms 22760 KB Output is correct
61 Correct 6 ms 23072 KB Output is correct
62 Correct 6 ms 22600 KB Output is correct
63 Correct 0 ms 22468 KB Output is correct
64 Correct 6 ms 22760 KB Output is correct
65 Correct 9 ms 22728 KB Output is correct
66 Correct 9 ms 22760 KB Output is correct
67 Correct 3 ms 22464 KB Output is correct
68 Correct 0 ms 22464 KB Output is correct
69 Correct 6 ms 22596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 22332 KB Output is correct
2 Correct 0 ms 22332 KB Output is correct
3 Correct 0 ms 22332 KB Output is correct
4 Correct 0 ms 22332 KB Output is correct
5 Correct 3 ms 22332 KB Output is correct
6 Correct 0 ms 22332 KB Output is correct
7 Correct 3 ms 22332 KB Output is correct
8 Correct 0 ms 22332 KB Output is correct
9 Correct 0 ms 22332 KB Output is correct
10 Correct 0 ms 22332 KB Output is correct
11 Correct 3 ms 22332 KB Output is correct
12 Correct 0 ms 22332 KB Output is correct
13 Correct 0 ms 22332 KB Output is correct
14 Correct 0 ms 22332 KB Output is correct
15 Correct 0 ms 22332 KB Output is correct
16 Correct 3 ms 22332 KB Output is correct
17 Correct 3 ms 22332 KB Output is correct
18 Correct 0 ms 22332 KB Output is correct
19 Correct 3 ms 22332 KB Output is correct
20 Correct 0 ms 22332 KB Output is correct
21 Correct 0 ms 22332 KB Output is correct
22 Correct 0 ms 22332 KB Output is correct
23 Correct 3 ms 22332 KB Output is correct
24 Correct 0 ms 22332 KB Output is correct
25 Correct 0 ms 22332 KB Output is correct
26 Correct 3 ms 22332 KB Output is correct
27 Correct 0 ms 22332 KB Output is correct
28 Correct 0 ms 22332 KB Output is correct
29 Correct 0 ms 22332 KB Output is correct
30 Correct 0 ms 22332 KB Output is correct
31 Correct 3 ms 22332 KB Output is correct
32 Correct 3 ms 22332 KB Output is correct
33 Correct 0 ms 22332 KB Output is correct
34 Correct 0 ms 22332 KB Output is correct
35 Correct 0 ms 22332 KB Output is correct
36 Correct 3 ms 22332 KB Output is correct
37 Correct 0 ms 22332 KB Output is correct
38 Correct 0 ms 22332 KB Output is correct
39 Correct 3 ms 22332 KB Output is correct
40 Correct 0 ms 22332 KB Output is correct
41 Correct 0 ms 22332 KB Output is correct
42 Correct 3 ms 22332 KB Output is correct
43 Correct 0 ms 22332 KB Output is correct
44 Correct 0 ms 22332 KB Output is correct
45 Correct 0 ms 22332 KB Output is correct
46 Correct 3 ms 22332 KB Output is correct
47 Correct 0 ms 22332 KB Output is correct
48 Correct 0 ms 22332 KB Output is correct
49 Correct 3 ms 22332 KB Output is correct
50 Correct 3 ms 22332 KB Output is correct
51 Correct 0 ms 22332 KB Output is correct
52 Correct 3 ms 22332 KB Output is correct
53 Correct 3 ms 22332 KB Output is correct
54 Correct 0 ms 22332 KB Output is correct
55 Correct 6 ms 22760 KB Output is correct
56 Correct 9 ms 23072 KB Output is correct
57 Correct 6 ms 22760 KB Output is correct
58 Correct 6 ms 22760 KB Output is correct
59 Correct 6 ms 22760 KB Output is correct
60 Correct 13 ms 22760 KB Output is correct
61 Correct 6 ms 23072 KB Output is correct
62 Correct 6 ms 22600 KB Output is correct
63 Correct 0 ms 22468 KB Output is correct
64 Correct 6 ms 22760 KB Output is correct
65 Correct 9 ms 22728 KB Output is correct
66 Correct 9 ms 22760 KB Output is correct
67 Correct 3 ms 22464 KB Output is correct
68 Correct 0 ms 22464 KB Output is correct
69 Correct 6 ms 22596 KB Output is correct
70 Correct 6 ms 22760 KB Output is correct
71 Correct 146 ms 28440 KB Output is correct
72 Correct 116 ms 39452 KB Output is correct
73 Correct 136 ms 28444 KB Output is correct
74 Correct 99 ms 30204 KB Output is correct
75 Correct 146 ms 28444 KB Output is correct
76 Correct 163 ms 28444 KB Output is correct
77 Correct 59 ms 25024 KB Output is correct
78 Correct 159 ms 28436 KB Output is correct
79 Correct 146 ms 28444 KB Output is correct
80 Correct 149 ms 39456 KB Output is correct
81 Correct 26 ms 23696 KB Output is correct
82 Correct 96 ms 26976 KB Output is correct
83 Correct 143 ms 28448 KB Output is correct
84 Correct 146 ms 28440 KB Output is correct
85 Correct 143 ms 28444 KB Output is correct
86 Correct 136 ms 28444 KB Output is correct
87 Correct 143 ms 27076 KB Output is correct
88 Correct 23 ms 23256 KB Output is correct
89 Correct 83 ms 25724 KB Output is correct
90 Correct 46 ms 26308 KB Output is correct
91 Correct 6 ms 22728 KB Output is correct
92 Correct 63 ms 26308 KB Output is correct