답안 #771542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771542 2023-07-03T06:15:18 Z canadavid1 저장 (Saveit) (IOI10_saveit) C++14
75 / 100
334 ms 14388 KB
#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
void encode_number(int n,int N, int H)
{
  for(int i = 1<<9; i > 0; i>>=1)
  {
    encode_bit((n&i)>0);
  }
}

int count1 = 0;
int count0 = 0;
int countm1 = 0;

void encode(int N, int H, int P, int *A, int *B)
{
  vector<vector<int>> neigh(N);
  for(int i = 0; i < P; i++)
  {
    neigh[A[i]].push_back(B[i]);
    neigh[B[i]].push_back(A[i]);
  }
  // BFS from all H
  vector<vector<int>> distance(H,vector<int>(N,INT_MAX));
  for(int h = 0; h < H; h++)
  {
    queue<pair<int,int>> q;
    q.push({h,0});
    while(q.size())
    {
      auto v = q.front();q.pop();
      if(distance[h][v.first]!=INT_MAX) continue;
      distance[h][v.first] = v.second;
      for(auto i : neigh[v.first]) q.push({i,v.second+1});
    }
  }
  vector<int> treep(N,-1);
  queue<int> q;
  q.push(0);
  while(q.size())
  {
    auto v = q.front();q.pop();
    for(auto i : neigh[v]) 
    {
      if(treep[i]!=-1) continue;
      treep[i] = v;
      q.push(i);
    }
  }


  for(int i = 1; i < N; i++)
  {
    int p = treep[i];
    encode_number(p,N,H);
  }
  for(int i = 1; i < N; i++)
  {
    int p = treep[i];
    for(int h=1; h < H; h++)
    {
      switch(distance[h][i]-distance[h][p])// mostly 1, sometimes -1, rarely 0
      {
      case 0:
        encode_bit(1);
        count0++;
        break;
      case 1:
        encode_bit(0);encode_bit(1);
        count1++;
        break;
      case -1:
        encode_bit(0);encode_bit(0);
        countm1++;
        break;
      }

    }
  }
  //cout << "counts = " << count1 << " " << count0 << " " << countm1 << "\n";
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
int decode_number(int N,int H)
{
    int o=0;
    for(int i = 0; i < 10; i++) o = (o<<1)+decode_bit();
    return o;
}

void decode(int N, int H) {
    vector<int> treep(N,-1);
    vector<vector<int>> treec(N);
    vector<vector<int>> distance(N,vector<int>(H,INT_MAX));
    vector<vector<int>> delta(N,vector<int>(H,0));
    for(int i = 0; i < H; i++) distance[i][i] = 0;
    for(int i = 1; i < N; i++)
    {
        treep[i] = decode_number(N, H);
        treec[treep[i]].push_back(i);
    }
    for(int i = 1; i < N; i++)
    {
        delta[i][0] = 1;
        for(int h = 1; h < H; h++)
        {
            if(decode_bit())
            {
                delta[i][h] = 0;
                continue;
            }
            if(decode_bit())
            {
                delta[i][h] = 1;
            }
            else
            {
                delta[i][h] = -1;
            }
        }
    }
    for(int h = 1; h < H; h++)
    {
        int c = 0;
        int t = h;
        while(t!=0)
        {
            c += delta[t][h];
            t = treep[t];
        }
        distance[0][h] = -c;
    }
    queue<int> q;
    for(auto i : treec[0]) q.push(i);
    while(q.size())
    {
        auto v = q.front(); q.pop();
        for(int h = 0; h < H; h++)
        {
            distance[v][h] = distance[treep[v]][h] + delta[v][h];
        }
        for(auto i : treec[v]) q.push(i);
    }
    for(int h = 0; h < H; h++)
        for(int c = 0; c < N; c++)
            hops(h,c,distance[c][h]);
        
}
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 14388 KB Output is correct - 62913 call(s) of encode_bit()
2 Correct 1 ms 4608 KB Output is correct - 52 call(s) of encode_bit()
3 Correct 18 ms 5756 KB Output is correct - 58901 call(s) of encode_bit()
4 Correct 2 ms 4600 KB Output is correct - 62 call(s) of encode_bit()
5 Correct 23 ms 5992 KB Output is correct - 56288 call(s) of encode_bit()
6 Correct 25 ms 5948 KB Output is correct - 60905 call(s) of encode_bit()
7 Correct 42 ms 6568 KB Output is correct - 50828 call(s) of encode_bit()
8 Correct 18 ms 5980 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 19 ms 6004 KB Output is partially correct - 78646 call(s) of encode_bit()
10 Correct 19 ms 6008 KB Output is partially correct - 78245 call(s) of encode_bit()
11 Correct 26 ms 6156 KB Output is partially correct - 76543 call(s) of encode_bit()
12 Correct 20 ms 6056 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 69 ms 6832 KB Output is correct - 58326 call(s) of encode_bit()
14 Correct 23 ms 6064 KB Output is partially correct - 77694 call(s) of encode_bit()
15 Correct 24 ms 6088 KB Output is partially correct - 76176 call(s) of encode_bit()
16 Correct 59 ms 6700 KB Output is partially correct - 72118 call(s) of encode_bit()
17 Correct 57 ms 6544 KB Output is partially correct - 74009 call(s) of encode_bit()
18 Correct 70 ms 6876 KB Output is correct - 69823 call(s) of encode_bit()
19 Correct 41 ms 6248 KB Output is correct - 66843 call(s) of encode_bit()
20 Correct 87 ms 7392 KB Output is correct - 63570 call(s) of encode_bit()
21 Correct 99 ms 7636 KB Output is correct - 64320 call(s) of encode_bit()
22 Correct 61 ms 6728 KB Output is correct - 53039 call(s) of encode_bit()
23 Correct 97 ms 8008 KB Output is correct - 56825 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 14388 KB Output is correct - 62913 call(s) of encode_bit()
2 Correct 1 ms 4608 KB Output is correct - 52 call(s) of encode_bit()
3 Correct 18 ms 5756 KB Output is correct - 58901 call(s) of encode_bit()
4 Correct 2 ms 4600 KB Output is correct - 62 call(s) of encode_bit()
5 Correct 23 ms 5992 KB Output is correct - 56288 call(s) of encode_bit()
6 Correct 25 ms 5948 KB Output is correct - 60905 call(s) of encode_bit()
7 Correct 42 ms 6568 KB Output is correct - 50828 call(s) of encode_bit()
8 Correct 18 ms 5980 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 19 ms 6004 KB Output is partially correct - 78646 call(s) of encode_bit()
10 Correct 19 ms 6008 KB Output is partially correct - 78245 call(s) of encode_bit()
11 Correct 26 ms 6156 KB Output is partially correct - 76543 call(s) of encode_bit()
12 Correct 20 ms 6056 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 69 ms 6832 KB Output is correct - 58326 call(s) of encode_bit()
14 Correct 23 ms 6064 KB Output is partially correct - 77694 call(s) of encode_bit()
15 Correct 24 ms 6088 KB Output is partially correct - 76176 call(s) of encode_bit()
16 Correct 59 ms 6700 KB Output is partially correct - 72118 call(s) of encode_bit()
17 Correct 57 ms 6544 KB Output is partially correct - 74009 call(s) of encode_bit()
18 Correct 70 ms 6876 KB Output is correct - 69823 call(s) of encode_bit()
19 Correct 41 ms 6248 KB Output is correct - 66843 call(s) of encode_bit()
20 Correct 87 ms 7392 KB Output is correct - 63570 call(s) of encode_bit()
21 Correct 99 ms 7636 KB Output is correct - 64320 call(s) of encode_bit()
22 Correct 61 ms 6728 KB Output is correct - 53039 call(s) of encode_bit()
23 Correct 97 ms 8008 KB Output is correct - 56825 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 14388 KB Output is correct - 62913 call(s) of encode_bit()
2 Correct 1 ms 4608 KB Output is correct - 52 call(s) of encode_bit()
3 Correct 18 ms 5756 KB Output is correct - 58901 call(s) of encode_bit()
4 Correct 2 ms 4600 KB Output is correct - 62 call(s) of encode_bit()
5 Correct 23 ms 5992 KB Output is correct - 56288 call(s) of encode_bit()
6 Correct 25 ms 5948 KB Output is correct - 60905 call(s) of encode_bit()
7 Correct 42 ms 6568 KB Output is correct - 50828 call(s) of encode_bit()
8 Correct 18 ms 5980 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 19 ms 6004 KB Output is partially correct - 78646 call(s) of encode_bit()
10 Correct 19 ms 6008 KB Output is partially correct - 78245 call(s) of encode_bit()
11 Correct 26 ms 6156 KB Output is partially correct - 76543 call(s) of encode_bit()
12 Correct 20 ms 6056 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 69 ms 6832 KB Output is correct - 58326 call(s) of encode_bit()
14 Correct 23 ms 6064 KB Output is partially correct - 77694 call(s) of encode_bit()
15 Correct 24 ms 6088 KB Output is partially correct - 76176 call(s) of encode_bit()
16 Correct 59 ms 6700 KB Output is partially correct - 72118 call(s) of encode_bit()
17 Correct 57 ms 6544 KB Output is partially correct - 74009 call(s) of encode_bit()
18 Correct 70 ms 6876 KB Output is correct - 69823 call(s) of encode_bit()
19 Correct 41 ms 6248 KB Output is correct - 66843 call(s) of encode_bit()
20 Correct 87 ms 7392 KB Output is correct - 63570 call(s) of encode_bit()
21 Correct 99 ms 7636 KB Output is correct - 64320 call(s) of encode_bit()
22 Correct 61 ms 6728 KB Output is correct - 53039 call(s) of encode_bit()
23 Correct 97 ms 8008 KB Output is correct - 56825 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 14388 KB Output is correct - 62913 call(s) of encode_bit()
2 Correct 1 ms 4608 KB Output is correct - 52 call(s) of encode_bit()
3 Correct 18 ms 5756 KB Output is correct - 58901 call(s) of encode_bit()
4 Correct 2 ms 4600 KB Output is correct - 62 call(s) of encode_bit()
5 Correct 23 ms 5992 KB Output is correct - 56288 call(s) of encode_bit()
6 Correct 25 ms 5948 KB Output is correct - 60905 call(s) of encode_bit()
7 Correct 42 ms 6568 KB Output is correct - 50828 call(s) of encode_bit()
8 Correct 18 ms 5980 KB Output is partially correct - 76800 call(s) of encode_bit()
9 Correct 19 ms 6004 KB Output is partially correct - 78646 call(s) of encode_bit()
10 Correct 19 ms 6008 KB Output is partially correct - 78245 call(s) of encode_bit()
11 Correct 26 ms 6156 KB Output is partially correct - 76543 call(s) of encode_bit()
12 Correct 20 ms 6056 KB Output is partially correct - 79920 call(s) of encode_bit()
13 Correct 69 ms 6832 KB Output is correct - 58326 call(s) of encode_bit()
14 Correct 23 ms 6064 KB Output is partially correct - 77694 call(s) of encode_bit()
15 Correct 24 ms 6088 KB Output is partially correct - 76176 call(s) of encode_bit()
16 Correct 59 ms 6700 KB Output is partially correct - 72118 call(s) of encode_bit()
17 Correct 57 ms 6544 KB Output is partially correct - 74009 call(s) of encode_bit()
18 Correct 70 ms 6876 KB Output is correct - 69823 call(s) of encode_bit()
19 Correct 41 ms 6248 KB Output is correct - 66843 call(s) of encode_bit()
20 Correct 87 ms 7392 KB Output is correct - 63570 call(s) of encode_bit()
21 Correct 99 ms 7636 KB Output is correct - 64320 call(s) of encode_bit()
22 Correct 61 ms 6728 KB Output is correct - 53039 call(s) of encode_bit()
23 Correct 97 ms 8008 KB Output is correct - 56825 call(s) of encode_bit()