답안 #578290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578290 2022-06-16T10:27:22 Z Theo830 자동 인형 (IOI18_doll) C++17
53 / 100
176 ms 18848 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e18+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "doll.h"
//void create_circuit(int M, std::vector<int> A);
//void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);
vector<int> X,Y,C;
ll pos = 1;
void solve(ll s,vll arr){
    if((ll)arr.size() == 1){
        X[s - 1] = -s;
        Y[s - 1] = arr[0];
        return;
    }
    if((ll)arr.size() == 2){
        X[s - 1] = arr[0];
        Y[s - 1] = arr[1];
        return;
    }
    vll exo[2];
    f(i,0,(ll)arr.size()){
        exo[i % 2].pb(arr[i]);
    }
    if((ll)arr.size() % 2){
        exo[1].pb(exo[0].back());
        exo[0].back() = -s;
        assert(exo[0].size() == exo[1].size());
    }
    X[s - 1] = -pos;
    Y[s - 1] = -(pos + 1);
    X.pb(0);
    X.pb(0);
    Y.pb(0);
    Y.pb(0);
    pos += 2;
    solve(-X[s - 1],exo[0]);
    solve(-Y[s - 1],exo[1]);
}
void create_circuit(int M, std::vector<int> A) {
      int n = A.size();
      f(i,0,M+1){
          C.pb(0);
      }
      C[0] = A[0];
      vll mp[M+5];
      set<ll>ex;
      A.pb(0);
      f(i,0,n){
        mp[A[i]].pb(A[i+1]);
      }
      set<ll>ev;
      f(i,0,n){
          if(ev.count(A[i])){
            continue;
          }
          ev.insert(A[i]);
          C[A[i]] = -pos;
          X.pb(0);
          Y.pb(0);
          pos++;
          solve(pos - 1,mp[A[i]]);
      }
      answer(C, X, Y);
}
/*
namespace {

constexpr int P_MAX = 20000000;
constexpr int S_MAX = 400000;

int M, N;
std::vector<int> A;

bool answered;
int S;
std::vector<int> IC, IX, IY;

int read_int() {
  int x;
  if (scanf("%d", &x) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  return x;
}

void wrong_answer(const char *MSG) {
  printf("Wrong Answer: %s\n", MSG);
  exit(0);
}

void simulate() {
  if (S > S_MAX) {
    char str[50];
    sprintf(str, "over %d switches", S_MAX);
    wrong_answer(str);
  }
  for (int i = 0; i <= M; ++i) {
    if (!(-S <= IC[i] && IC[i] <= M)) {
      wrong_answer("wrong serial number");
    }
  }
  for (int j = 1; j <= S; ++j) {
    if (!(-S <= IX[j - 1] && IX[j - 1] <= M)) {
      wrong_answer("wrong serial number");
    }
    if (!(-S <= IY[j - 1] && IY[j - 1] <= M)) {
      wrong_answer("wrong serial number");
    }
  }

  int P = 0;
  std::vector<bool> state(S + 1, false);
  int pos = IC[0];
  int k = 0;
  FILE *file_log = fopen("log.txt", "w");
  fprintf(file_log, "0\n");
  for (;;) {
    fprintf(file_log, "%d\n", pos);
    if (pos < 0) {
      if (++P > P_MAX) {
        fclose(file_log);
        char str[50];
        sprintf(str, "over %d inversions", P_MAX);
        wrong_answer(str);
      }
      state[-pos] = !state[-pos];
      pos = state[-pos] ? IX[-(1 + pos)] : IY[-(1 + pos)];
    } else {
      if (pos == 0) {
        break;
      }
      if (k >= N) {
        fclose(file_log);
        wrong_answer("wrong motion");
      }
      if (pos != A[k++]) {
        fclose(file_log);
        wrong_answer("wrong motion");
      }
      pos = IC[pos];
    }
  }
  fclose(file_log);
  if (k != N) {
    wrong_answer("wrong motion");
  }
  for (int j = 1; j <= S; ++j) {
    if (state[j]) {
      wrong_answer("state 'Y'");
    }
  }
  printf("Accepted: %d %d\n", S, P);
}

}  // namespace

void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y) {
  if (answered) {
    wrong_answer("answered not exactly once");
  }
  answered = true;
  // check if input format is correct
  if ((int)C.size() != M + 1) {
    wrong_answer("wrong array length");
  }
  if (X.size() != Y.size()) {
    wrong_answer("wrong array length");
  }
  S = X.size();
  IC = C;
  IX = X;
  IY = Y;
}

int main() {
  M = read_int();
  N = read_int();
  A.resize(N);
  for (int k = 0; k < N; ++k) {
    A[k] = read_int();
  }

  answered = false;
  create_circuit(M, A);
  if (!answered) {
    wrong_answer("answered not exactly once");
  }
  FILE *file_out = fopen("out.txt", "w");
  fprintf(file_out, "%d\n", S);
  for (int i = 0; i <= M; ++i) {
    fprintf(file_out, "%d\n", IC[i]);
  }
  for (int j = 1; j <= S; ++j) {
    fprintf(file_out, "%d %d\n", IX[j - 1], IY[j - 1]);
  }
  fclose(file_out);
  simulate();
  return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 67 ms 11656 KB Output is correct
3 Correct 69 ms 10784 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 12 ms 3916 KB Output is correct
6 Correct 108 ms 16432 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 67 ms 11656 KB Output is correct
3 Correct 69 ms 10784 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 12 ms 3916 KB Output is correct
6 Correct 108 ms 16432 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 95 ms 11008 KB Output is correct
9 Correct 116 ms 15856 KB Output is correct
10 Correct 142 ms 17436 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 67 ms 11656 KB Output is correct
3 Correct 69 ms 10784 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 12 ms 3916 KB Output is correct
6 Correct 108 ms 16432 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 95 ms 11008 KB Output is correct
9 Correct 116 ms 15856 KB Output is correct
10 Correct 142 ms 17436 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 160 ms 18848 KB Output is correct
15 Correct 77 ms 9788 KB Output is correct
16 Correct 137 ms 14652 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 162 ms 18608 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 62 ms 8716 KB Output is correct
3 Partially correct 99 ms 13336 KB Output is partially correct
4 Partially correct 118 ms 13716 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 62 ms 8716 KB Output is correct
3 Partially correct 99 ms 13336 KB Output is partially correct
4 Partially correct 118 ms 13716 KB Output is partially correct
5 Partially correct 174 ms 16492 KB Output is partially correct
6 Partially correct 171 ms 17004 KB Output is partially correct
7 Partially correct 176 ms 16576 KB Output is partially correct
8 Partially correct 167 ms 17392 KB Output is partially correct
9 Partially correct 99 ms 10880 KB Output is partially correct
10 Partially correct 153 ms 17184 KB Output is partially correct
11 Partially correct 161 ms 15140 KB Output is partially correct
12 Partially correct 99 ms 11560 KB Output is partially correct
13 Partially correct 123 ms 11768 KB Output is partially correct
14 Partially correct 107 ms 11348 KB Output is partially correct
15 Partially correct 103 ms 10904 KB Output is partially correct
16 Partially correct 3 ms 564 KB Output is partially correct
17 Partially correct 87 ms 9620 KB Output is partially correct
18 Partially correct 84 ms 9596 KB Output is partially correct
19 Partially correct 96 ms 9320 KB Output is partially correct
20 Partially correct 143 ms 13028 KB Output is partially correct
21 Partially correct 153 ms 13468 KB Output is partially correct
22 Partially correct 116 ms 11464 KB Output is partially correct