Submission #220834

# Submission time Handle Problem Language Result Execution time Memory
220834 2020-04-09T02:38:29 Z Lawliet Saveit (IOI10_saveit) C++17
0 / 100
246 ms 12272 KB
#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;

const int MAXH = 40;
const int MAXN = 1010;

int dad[MAXN][MAXH];
int dist[MAXN][MAXH];

bool marc[MAXN][MAXH];

vector< int > adj[MAXN];

queue< int > q;

bool isActive(lli mask, int k) { return mask & (1LL << k); }

void print(lli val, int b)
{
	for(int i = 0 ; i < b ; i++)
	{
		if( isActive( val , i ) ) encode_bit( 1 );
		else encode_bit( 0 );
	}
}

void add(int cur, int d, int p, int ind)
{
	q.push( cur );

	dad[cur][ind] = p;
	dist[cur][ind] = d;
	marc[cur][ind] = true;
}

void BFS(int source, int ind, bool needPrint = false)
{
	add( source , 0 , source , ind );

	while( !q.empty() )
	{
		int cur = q.front();
		q.pop();

		if( needPrint && cur != 0 )
			print( dad[cur][0] , 10 );

		for(int i = 0 ; i < adj[cur].size() ; i++)
		{
			int viz = adj[cur][i];

			if( marc[viz][ind] ) continue;

			add( viz , dist[cur][ind] + 1 , cur , ind );
		}
	}
}

void encode(int N, int H, int E, int *U, int *V)
{
	for(int i = 0 ; i < E ; i++)
	{
		adj[ U[i] ].push_back( V[i] );
		adj[ V[i] ].push_back( U[i] );
	}

	BFS( 0 , 0 , true );

	for(int j = 1 ; j < H ; j++)
	{
		BFS( j , j );
		print( dist[0][j] , 10 );
	}

	for(int i = 1 ; i < N ; i++)
	{
		int U = i;
		int V = dad[i][0];

		lli sum = 0;

		for(int j = 1 ; j < H ; j++)
		{
			lli v;
			if( dist[U][j] < dist[V][j] ) v = 0;
			if( dist[U][j] == dist[V][j] ) v = 1;
			if( dist[U][j] > dist[V][j] ) v = 2;

			sum = 3*sum + v;
		}

		print( sum , 56 );
	}
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;

const int MAXH = 40;
const int MAXN = 1010;

int dist[MAXN][MAXH];

vector< int > adj[MAXN];
vector< int > digits[MAXN];

lli read(int b)
{
	lli val = 0;

	for(int i = 0 ; i < b ; i++)
	{
		int curBit = decode_bit();
		if( curBit == 1 ) val += (1LL << i);
	}

	return val;
}

void toTernaryBase(lli val, int edge, int H)
{
	lli curPot = 1;

	for(int i = 0 ; i < H - 2 ; i++)
		curPot *= 3;

	for(int i = 0 ; i < H - 1 ; i++, curPot /= 3)
	{
		for(int j = 1 ; j <= 3 ; j++)
		{
			if( val < j*curPot )
			{
				digits[edge].push_back( j - 1 );
				val -= (j - 1)*curPot;

				break;
			}
		}
	}
}

void DFS(int cur, int H)
{
	for(int i = 0 ; i < adj[cur].size() ; i++)
	{
		int viz = adj[cur][i];

		for(int j = 0 ; j < H ; j++)
			dist[viz][j] = dist[cur][j] + digits[viz][j] - 1;

		DFS( viz , H );
	}
}

void decode(int N, int H) 
{
	for(int i = 1 ; i < N ; i++)
		adj[ read(10) ].push_back( i );

	for(int i = 1 ; i < H ; i++)
		dist[0][i] = read(10);

	for(int i = 0 ; i < N - 1 ; i++)
	{
		lli diffDist = read(56);

		digits[i + 1].push_back( 2 );
		toTernaryBase( diffDist , i + 1 , H );
	}

	DFS( 0 , H );

	for(int i = 0 ; i < N ; i++)
		for(int j = 0 ; j < H ; j++)
			hops( j , i , dist[i][j] );
}

Compilation message

encoder.cpp: In function 'void BFS(int, int, bool)':
encoder.cpp:52:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < adj[cur].size() ; i++)
                   ~~^~~~~~~~~~~~~~~~~
encoder.cpp: In function 'void encode(int, int, int, int*, int*)':
encoder.cpp:93:8: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
    sum = 3*sum + v;
    ~~~~^~~~~~~~~~~

decoder.cpp: In function 'void DFS(int, int)':
decoder.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < adj[cur].size() ; i++)
                  ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 246 ms 12272 KB wrong parameter
2 Correct 11 ms 4720 KB Output is correct - 284 call(s) of encode_bit()
3 Incorrect 34 ms 6016 KB Output isn't correct
4 Correct 12 ms 4736 KB Output is correct - 304 call(s) of encode_bit()
5 Incorrect 37 ms 6512 KB wrong parameter
6 Incorrect 38 ms 6372 KB Output isn't correct
7 Incorrect 49 ms 7024 KB wrong parameter
8 Incorrect 38 ms 6152 KB Output isn't correct
9 Incorrect 36 ms 6144 KB Output isn't correct
10 Incorrect 36 ms 6272 KB Output isn't correct
11 Incorrect 39 ms 6612 KB Output isn't correct
12 Incorrect 39 ms 6080 KB Output isn't correct
13 Incorrect 57 ms 6784 KB wrong parameter
14 Incorrect 40 ms 6176 KB Output isn't correct
15 Incorrect 41 ms 6504 KB Output isn't correct
16 Incorrect 63 ms 6776 KB Output isn't correct
17 Incorrect 49 ms 6788 KB wrong parameter
18 Incorrect 62 ms 6928 KB Output isn't correct
19 Incorrect 46 ms 6692 KB Output isn't correct
20 Incorrect 67 ms 7072 KB Output isn't correct
21 Incorrect 77 ms 7864 KB wrong parameter
22 Incorrect 56 ms 7016 KB wrong parameter
23 Incorrect 90 ms 7636 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 246 ms 12272 KB wrong parameter
2 Correct 11 ms 4720 KB Output is correct - 284 call(s) of encode_bit()
3 Incorrect 34 ms 6016 KB Output isn't correct
4 Correct 12 ms 4736 KB Output is correct - 304 call(s) of encode_bit()
5 Incorrect 37 ms 6512 KB wrong parameter
6 Incorrect 38 ms 6372 KB Output isn't correct
7 Incorrect 49 ms 7024 KB wrong parameter
8 Incorrect 38 ms 6152 KB Output isn't correct
9 Incorrect 36 ms 6144 KB Output isn't correct
10 Incorrect 36 ms 6272 KB Output isn't correct
11 Incorrect 39 ms 6612 KB Output isn't correct
12 Incorrect 39 ms 6080 KB Output isn't correct
13 Incorrect 57 ms 6784 KB wrong parameter
14 Incorrect 40 ms 6176 KB Output isn't correct
15 Incorrect 41 ms 6504 KB Output isn't correct
16 Incorrect 63 ms 6776 KB Output isn't correct
17 Incorrect 49 ms 6788 KB wrong parameter
18 Incorrect 62 ms 6928 KB Output isn't correct
19 Incorrect 46 ms 6692 KB Output isn't correct
20 Incorrect 67 ms 7072 KB Output isn't correct
21 Incorrect 77 ms 7864 KB wrong parameter
22 Incorrect 56 ms 7016 KB wrong parameter
23 Incorrect 90 ms 7636 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 246 ms 12272 KB wrong parameter
2 Correct 11 ms 4720 KB Output is correct - 284 call(s) of encode_bit()
3 Incorrect 34 ms 6016 KB Output isn't correct
4 Correct 12 ms 4736 KB Output is correct - 304 call(s) of encode_bit()
5 Incorrect 37 ms 6512 KB wrong parameter
6 Incorrect 38 ms 6372 KB Output isn't correct
7 Incorrect 49 ms 7024 KB wrong parameter
8 Incorrect 38 ms 6152 KB Output isn't correct
9 Incorrect 36 ms 6144 KB Output isn't correct
10 Incorrect 36 ms 6272 KB Output isn't correct
11 Incorrect 39 ms 6612 KB Output isn't correct
12 Incorrect 39 ms 6080 KB Output isn't correct
13 Incorrect 57 ms 6784 KB wrong parameter
14 Incorrect 40 ms 6176 KB Output isn't correct
15 Incorrect 41 ms 6504 KB Output isn't correct
16 Incorrect 63 ms 6776 KB Output isn't correct
17 Incorrect 49 ms 6788 KB wrong parameter
18 Incorrect 62 ms 6928 KB Output isn't correct
19 Incorrect 46 ms 6692 KB Output isn't correct
20 Incorrect 67 ms 7072 KB Output isn't correct
21 Incorrect 77 ms 7864 KB wrong parameter
22 Incorrect 56 ms 7016 KB wrong parameter
23 Incorrect 90 ms 7636 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 246 ms 12272 KB wrong parameter
2 Correct 11 ms 4720 KB Output is correct - 284 call(s) of encode_bit()
3 Incorrect 34 ms 6016 KB Output isn't correct
4 Correct 12 ms 4736 KB Output is correct - 304 call(s) of encode_bit()
5 Incorrect 37 ms 6512 KB wrong parameter
6 Incorrect 38 ms 6372 KB Output isn't correct
7 Incorrect 49 ms 7024 KB wrong parameter
8 Incorrect 38 ms 6152 KB Output isn't correct
9 Incorrect 36 ms 6144 KB Output isn't correct
10 Incorrect 36 ms 6272 KB Output isn't correct
11 Incorrect 39 ms 6612 KB Output isn't correct
12 Incorrect 39 ms 6080 KB Output isn't correct
13 Incorrect 57 ms 6784 KB wrong parameter
14 Incorrect 40 ms 6176 KB Output isn't correct
15 Incorrect 41 ms 6504 KB Output isn't correct
16 Incorrect 63 ms 6776 KB Output isn't correct
17 Incorrect 49 ms 6788 KB wrong parameter
18 Incorrect 62 ms 6928 KB Output isn't correct
19 Incorrect 46 ms 6692 KB Output isn't correct
20 Incorrect 67 ms 7072 KB Output isn't correct
21 Incorrect 77 ms 7864 KB wrong parameter
22 Incorrect 56 ms 7016 KB wrong parameter
23 Incorrect 90 ms 7636 KB Output isn't correct