Submission #64900

# Submission time Handle Problem Language Result Execution time Memory
64900 2018-08-06T05:45:00 Z funcsr Xylophone (JOI18_xylophone) C++17
100 / 100
197 ms 20892 KB
#include "xylophone.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[5000];
bool used[5000];
int cache[5000][5000];
bool ok(int x) {
  return x>=0 && x<N && !used[x];
}
void setA(int pos, int val) {
  assert(ok(val));
  used[val] = true;
  A[pos] = val;
}

int ask(int l, int r) {
  if (l > r) swap(l, r);
  if (l == r) return 0;
  if (cache[l][r]) return cache[l][r];
  return cache[l][r] = query(l+1, r+1);
}
int f(int a, int b, int d, int m) {
  if (a < b) {
    if (b+d-a == m) return b+d;
    else return b-d;
  }
  else {
    if (a-(b-d) == m) return b-d;
    else return b+d;
  }
}

void solve(int NN) {
  N = NN;
  int lo = 0, hi = N-1;
  while (hi-lo > 1) {
    int mid = (lo+hi)/2;
    if (ask(0, mid) == N-1) hi = mid;
    else lo = mid;
  }
  rep(i, N) A[i] = -1;
  setA(hi, N-1);
  setA(hi-1, N-1-ask(hi-1, hi));

  for (int i=hi+1; i<N; i++) {
    //cout<<A[i-2]<<","<<A[i-1]<<",?\n";
    int d = ask(i-1, i);
    vector<int> qs;
    if (ok(A[i-1]+d)) qs.pb(A[i-1]+d);
    if (ok(A[i-1]-d)) qs.pb(A[i-1]-d);
    if (qs.size()==2) {
      qs.clear();
      qs.pb(f(A[i-2], A[i-1], d, ask(i-2, i)));
    }
    assert(qs.size() == 1);
    setA(i, qs[0]);
  }
  for (int i=hi-2; i>=0; i--) {
    //cout<<"?,"<<A[i+1]<<","<<A[i+2]<<"\n";
    int d = ask(i, i+1);
    vector<int> qs;
    if (ok(A[i+1]+d)) qs.pb(A[i+1]+d);
    if (ok(A[i+1]-d)) qs.pb(A[i+1]-d);
    if (qs.size()==2) {
      qs.clear();
      qs.pb(f(A[i+2], A[i+1], d, ask(i, i+2)));
    }
    assert(qs.size() == 1);
    setA(i, qs[0]);
  }
  //rep(i, N) cout << A[i]<<",";cout<<"\n";
  rep(i, N) answer(i+1, A[i]+1);
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 3 ms 948 KB Output is correct
6 Correct 4 ms 948 KB Output is correct
7 Correct 5 ms 948 KB Output is correct
8 Correct 5 ms 948 KB Output is correct
9 Correct 4 ms 956 KB Output is correct
10 Correct 5 ms 956 KB Output is correct
11 Correct 6 ms 956 KB Output is correct
12 Correct 5 ms 956 KB Output is correct
13 Correct 5 ms 956 KB Output is correct
14 Correct 5 ms 956 KB Output is correct
15 Correct 5 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 3 ms 948 KB Output is correct
6 Correct 4 ms 948 KB Output is correct
7 Correct 5 ms 948 KB Output is correct
8 Correct 5 ms 948 KB Output is correct
9 Correct 4 ms 956 KB Output is correct
10 Correct 5 ms 956 KB Output is correct
11 Correct 6 ms 956 KB Output is correct
12 Correct 5 ms 956 KB Output is correct
13 Correct 5 ms 956 KB Output is correct
14 Correct 5 ms 956 KB Output is correct
15 Correct 5 ms 956 KB Output is correct
16 Correct 7 ms 1468 KB Output is correct
17 Correct 18 ms 2416 KB Output is correct
18 Correct 22 ms 3772 KB Output is correct
19 Correct 29 ms 4540 KB Output is correct
20 Correct 23 ms 4540 KB Output is correct
21 Correct 23 ms 4540 KB Output is correct
22 Correct 20 ms 4544 KB Output is correct
23 Correct 20 ms 4544 KB Output is correct
24 Correct 19 ms 4544 KB Output is correct
25 Correct 12 ms 4544 KB Output is correct
26 Correct 21 ms 4608 KB Output is correct
27 Correct 22 ms 4608 KB Output is correct
28 Correct 26 ms 4608 KB Output is correct
29 Correct 26 ms 4608 KB Output is correct
30 Correct 27 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 5 ms 896 KB Output is correct
5 Correct 3 ms 948 KB Output is correct
6 Correct 4 ms 948 KB Output is correct
7 Correct 5 ms 948 KB Output is correct
8 Correct 5 ms 948 KB Output is correct
9 Correct 4 ms 956 KB Output is correct
10 Correct 5 ms 956 KB Output is correct
11 Correct 6 ms 956 KB Output is correct
12 Correct 5 ms 956 KB Output is correct
13 Correct 5 ms 956 KB Output is correct
14 Correct 5 ms 956 KB Output is correct
15 Correct 5 ms 956 KB Output is correct
16 Correct 7 ms 1468 KB Output is correct
17 Correct 18 ms 2416 KB Output is correct
18 Correct 22 ms 3772 KB Output is correct
19 Correct 29 ms 4540 KB Output is correct
20 Correct 23 ms 4540 KB Output is correct
21 Correct 23 ms 4540 KB Output is correct
22 Correct 20 ms 4544 KB Output is correct
23 Correct 20 ms 4544 KB Output is correct
24 Correct 19 ms 4544 KB Output is correct
25 Correct 12 ms 4544 KB Output is correct
26 Correct 21 ms 4608 KB Output is correct
27 Correct 22 ms 4608 KB Output is correct
28 Correct 26 ms 4608 KB Output is correct
29 Correct 26 ms 4608 KB Output is correct
30 Correct 27 ms 4608 KB Output is correct
31 Correct 48 ms 9340 KB Output is correct
32 Correct 60 ms 12988 KB Output is correct
33 Correct 104 ms 18136 KB Output is correct
34 Correct 72 ms 20752 KB Output is correct
35 Correct 73 ms 20776 KB Output is correct
36 Correct 82 ms 20888 KB Output is correct
37 Correct 57 ms 20888 KB Output is correct
38 Correct 74 ms 20888 KB Output is correct
39 Correct 100 ms 20888 KB Output is correct
40 Correct 119 ms 20888 KB Output is correct
41 Correct 62 ms 20888 KB Output is correct
42 Correct 81 ms 20888 KB Output is correct
43 Correct 84 ms 20888 KB Output is correct
44 Correct 107 ms 20888 KB Output is correct
45 Correct 112 ms 20892 KB Output is correct
46 Correct 139 ms 20892 KB Output is correct
47 Correct 82 ms 20892 KB Output is correct
48 Correct 65 ms 20892 KB Output is correct
49 Correct 146 ms 20892 KB Output is correct
50 Correct 132 ms 20892 KB Output is correct
51 Correct 148 ms 20892 KB Output is correct
52 Correct 142 ms 20892 KB Output is correct
53 Correct 197 ms 20892 KB Output is correct
54 Correct 140 ms 20892 KB Output is correct
55 Correct 70 ms 20892 KB Output is correct
56 Correct 137 ms 20892 KB Output is correct
57 Correct 125 ms 20892 KB Output is correct
58 Correct 64 ms 20892 KB Output is correct
59 Correct 110 ms 20892 KB Output is correct
60 Correct 135 ms 20892 KB Output is correct