답안 #1074292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074292 2024-08-25T09:27:19 Z Victor 자동 인형 (IOI18_doll) C++17
37 / 100
77 ms 19840 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include "doll.h"

using namespace std;

#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define per(i, a, b) for (ll i = (b) - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) (ll)x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;

const ll INF = 1'000'000'007;

ll m,n;
vll a;
vector<vll> triggers;
vll c,x,y;

ll scnt=0;

void create_circuit(int M, std::vector<int> A) {
    m=M;
    n=sz(A);

    trav(i,A) a.pb(i);
    c.assign(m+1,-1);

    ll cnt=n;
    while(__builtin_popcountll(cnt)!=1||cnt==n) {
        ++cnt;
        a.pb(-1);
    }
    a.back()=0;

    ll bits=__builtin_ctzll(cnt);

    ll triggerpos=0;
    rep(i,1,cnt/2) {
        x.pb(-(2*i));
        y.pb(-(2*i+1));
    }

    rep(i,cnt/2,cnt) {
        ll rev1=0;
        rep(k,0,bits) if((1<<k)&triggerpos) rev1+=(1<<(bits-k-1));
        ++triggerpos;

        ll rev2=0;
        rep(k,0,bits) if((1<<k)&triggerpos) rev2+=(1<<(bits-k-1));
        ++triggerpos;

        x.pb(a[rev1]);
        y.pb(a[rev2]);
    }

    vi C,X,Y;
    trav(i,c) C.pb(i);
    trav(i,x) X.pb(i);
    trav(i,y) Y.pb(i);
    answer(C,X,Y);
}

/**
#include <cstdio>
#include <cstdlib>


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;
}/**/

Compilation message

doll.cpp:224:2: warning: "/*" within comment [-Wcomment]
  224 | }/**/
      |
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Partially correct 62 ms 17640 KB Output is partially correct
3 Partially correct 64 ms 18028 KB Output is partially correct
4 Partially correct 64 ms 18400 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Partially correct 62 ms 17640 KB Output is partially correct
3 Partially correct 64 ms 18028 KB Output is partially correct
4 Partially correct 64 ms 18400 KB Output is partially correct
5 Partially correct 72 ms 19840 KB Output is partially correct
6 Partially correct 68 ms 19632 KB Output is partially correct
7 Partially correct 66 ms 19608 KB Output is partially correct
8 Partially correct 66 ms 19576 KB Output is partially correct
9 Partially correct 56 ms 17716 KB Output is partially correct
10 Partially correct 66 ms 19116 KB Output is partially correct
11 Partially correct 61 ms 18972 KB Output is partially correct
12 Partially correct 60 ms 18104 KB Output is partially correct
13 Partially correct 59 ms 18364 KB Output is partially correct
14 Partially correct 64 ms 18568 KB Output is partially correct
15 Partially correct 64 ms 18748 KB Output is partially correct
16 Partially correct 2 ms 860 KB Output is partially correct
17 Correct 37 ms 9964 KB Output is correct
18 Partially correct 61 ms 17856 KB Output is partially correct
19 Partially correct 60 ms 17952 KB Output is partially correct
20 Partially correct 77 ms 19040 KB Output is partially correct
21 Partially correct 63 ms 18864 KB Output is partially correct
22 Partially correct 68 ms 18864 KB Output is partially correct