답안 #1026496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026496 2024-07-18T07:01:01 Z Malix 자동 인형 (IOI18_doll) C++14
24 / 100
75 ms 12996 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))

ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;

void create_circuit(int M, std::vector<int> A) {
  int n=A.size();
  vi c,x,y;
  vi p;
  REP(i,0,21)p.PB(pow(2,i));
  c.resize(M+1,0);
  c[0]=A[0]; 
  vi a(M+1,0);
  vii b(M+1);
  REP(i,0,n)a[A[i]]++;
  REP(i,0,n-1)b[A[i]].PB(A[i+1]);
  b[A[n-1]].PB(0);
  int k=0;
  REP(j,1,M+1){
    if(a[j]==0)continue;
    if(a[j]==1)c[j]=b[j][0];
    else if(a[j]==2){
      c[j]=k-1;
      k--;
      x.PB(b[j][0]);
      y.PB(b[j][1]);
    }
    else{
        c[j]=k-1;
        k--;
        vi x1,y1;
        auto it=lower_bound(p.begin(),p.end(),a[j]);
        int k1=log2(*it);
        int pos=k;
        int t=0;
        x1.PB(inf);y1.PB(inf);
        REP(i,0,k1-1){
          REP(v,0,pow(2,i)){
            t++;
            x1.PB(pos-1);
            y1.PB(pos-2);
            pos-=2;
          }
        }
        REP(v,0,pow(2,k1-1)){
            x1.PB(k);
            y1.PB(k);
        }
        vi arr(*it,0);
        int g=*it;
        int pp=0;
        int r=0;
        while(g){
          g/=2;
          while(pp<*it){
            pp+=g;
            REP(i,pp,pp+g)arr[i]|=(1<<r);
            pp+=g;
          }
          r++;
        }
        pii brr;
        REP(i,1,a[j]+1)brr.PB({arr[*it-i],*it-i});
        sort(brr.begin(),brr.end());
        REP(i,0,a[j]){
          if(brr[i].S%2==0)x1[t+brr[i].S/2+1]=b[j][i];
          else y1[t+brr[i].S/2+1]=b[j][i];
        }
        int s=x1.size();
        for(int i=s-1;i>=1;i--)if(x1[i]==k&&y1[i]==k){
          x1[i]=inf;y1[i]=inf;
          if(i%2==0)x1[i/2]=k;
          else y1[i/2]=k;
        }
        pos=k;
        REP(i,1,s){
          if(x1[i]!=pos&&x1[i]!=inf){
            if(x1[i]<0)x.PB(k-1);
            else x.PB(x1[i]);
            k--;
          }
          else if(x1[i]!=inf)x.PB(pos);
          if(y1[i]!=pos&&y1[i]!=inf){
            if(y1[i]<0)y.PB(k-1);
            else y.PB(y1[i]);
            k--;
          }
          else if(y1[i]!=inf)y.PB(pos);
        }
    }
  }
  // for(auto u:c)cerr<<u<<" ";
  // cerr<<"\n";
  // for(auto u:x)cerr<<u<<" ";
  // cerr<<"\n";
  // for(auto u:y)cerr<<u<<" ";
  // cerr<<"\n";
  answer(c,x,y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 18 ms 7212 KB Output is correct
3 Correct 15 ms 6020 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 6 ms 4188 KB Output is correct
6 Correct 23 ms 8792 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 18 ms 7212 KB Output is correct
3 Correct 15 ms 6020 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 6 ms 4188 KB Output is correct
6 Correct 23 ms 8792 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 29 ms 8396 KB Output is correct
9 Correct 33 ms 9936 KB Output is correct
10 Correct 47 ms 12996 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 18 ms 7212 KB Output is correct
3 Correct 15 ms 6020 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 6 ms 4188 KB Output is correct
6 Correct 23 ms 8792 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 29 ms 8396 KB Output is correct
9 Correct 33 ms 9936 KB Output is correct
10 Correct 47 ms 12996 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 70 ms 12736 KB wrong serial number
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB wrong serial number
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 31 ms 6680 KB Output is correct
3 Correct 39 ms 9332 KB Output is correct
4 Correct 49 ms 11640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 31 ms 6680 KB Output is correct
3 Correct 39 ms 9332 KB Output is correct
4 Correct 49 ms 11640 KB Output is correct
5 Incorrect 75 ms 12864 KB wrong serial number
6 Halted 0 ms 0 KB -