답안 #341768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341768 2020-12-31T00:48:06 Z ogibogi2004 저장 (Saveit) (IOI10_saveit) C++14
100 / 100
285 ms 15328 KB
#include "grader.h"
#include "encoder.h"
#include<bits/stdc++.h>
using namespace std;
string s;
int dist[40][1024];
vector<int>g[1024];
vector<int>g1[1024];
int par[1024];
int f[1024][40];
void bfs(int u)
{
	queue<int>q;
	q.push(u);
	for(int i=0;i<1024;i++)
	{
		dist[u][i]=100000;
	}
	dist[u][u]=0;
	while(!q.empty())
	{
		int u1=q.front();
		q.pop();
		for(auto v:g[u1])
		{
			if(dist[u][u1]+1<dist[u][v])
			{
				dist[u][v]=dist[u][u1]+1;
				q.push(v);
			}
		}
	}
}
bool vis[1024];
void dfs(int u,int p)
{
	vis[u]=1;
	par[u]=p;
	for(auto v:g[u])
	{
		if(vis[v])continue;
		dfs(v,u);
	}
}
void encode(int nv, int nh, int ne, int *v1, int *v2){
  for(int i=0;i<ne;i++)
  {
	  g[v1[i]].push_back(v2[i]);
	  g[v2[i]].push_back(v1[i]);
  }
  for(int i=0;i<nh;i++)
  {
	  bfs(i);
  }
  dfs(0,-1);
  for(int i=1;i<nv;i++)
  {
	  for(int j=0;j<nh;j++)
	  {
		  f[i][j]=dist[j][i]-dist[j][par[i]];
	  }
  }
  for(int i=1;i<nv;i++)
  {
	  for(int l=0;l<10;l++)
	  {
		  if(par[i]&(1<<l))s+="1";
		  else s+="0";
	  }
  }
  for(int l=0;l<nh;l++)
  {
	  for(int k=0;k<10;k++)
	  {
		  if(dist[l][0]&(1<<k))s+="1";
		  else s+="0";
	  }
	  for(int i=1;i<nv;i+=5)
	  {
		  int p=0;
		  p=(f[i][l]+1)*81+(f[i+1][l]+1)*27+(f[i+2][l]+1)*9+(f[i+3][l]+1)*3+f[i+4][l]+1;
		  for(int j=0;j<8;j++)
		  {
			  if(p&(1<<j))
			  {
				  s+="1";
			  }
			  else s+="0";
		  }
	  }
  }
  /*for(int i=0;i<nh;i++)
  {
	  for(int j=i+1;j<nh;j++)
	  {
		  for(int l=0;l<10;l++)
		  {
			  if((1<<l)&dist[i][j])
			  {
				  s+='1';
			  }
			  else s+='0';
		  }
	  }
  }
  for(int i=nh;i<nv;i++)
  {
	  int smallest=100000;
	  vector<int>v;
	  for(int j=0;j<nh;j++)
	  {
		  if(dist[j][i]<smallest)
		  {
			  smallest=dist[j][i];
			  v.clear();
		  }
		  if(dist[j][i]==smallest)
		  {
			  v.push_back(j);
		  }
	  }
	  bool b[40];
	  memset(b,0,sizeof(b));
	  for(auto xd:v)b[xd]=1;
	  for(int l=0;l<nh;l++)
	  {
		  if(b[l])s+="1";
		  else s+="0";
	  }
	  for(int l=0;l<10;l++)
	  {
		  if((1<<l)&smallest)
		  {
			  s+="1";
		  }
		  else s+="0";
	  }
  }*/
  for(int i=0;i<s.size();i++)encode_bit((int)s[i]-'0');
  return;
}
#include "grader.h"
#include "decoder.h"
#include<bits/stdc++.h>
using namespace std;
int dist[1024][1024];
int dist_to_closest[1024];
vector<int>closest[1024];
int par[1024];
vector<int>g[1024];
int f[1024][64];
int gg;
void dfs(int u)
{
	for(auto v:g[u])
	{
		for(int j=0;j<gg;j++)
		{
			dist[v][j]=dist[u][j]+f[v][j];
		}
		dfs(v);
	}
}
void decode(int nv, int nh) {
	gg=nh;
	memset(dist,0,sizeof(dist));
	memset(f,0,sizeof(f));
	memset(par,0,sizeof(par));
	for(int i=0;i<nv;i++)g[i].clear();
	for(int i=1;i<nv;i++)
	{
		int p=0;
		for(int l=0;l<10;l++)
		{
			int x=decode_bit();
			p+=(x<<l);
		}
		par[i]=p;
		g[p].push_back(i);
	}
	for(int i=0;i<nh;i++)
	{
		for(int l=0;l<10;l++)
		{
			int x=decode_bit();
			dist[0][i]+=(x<<l);
		}
		for(int j=1;j<nv;j+=5)
		{
			int p=0;
			for(int l=0;l<8;l++)
			{
				int x=decode_bit();
				p+=(x<<l);
			}
			f[j][i]=p/81-1;
			f[j+1][i]=(p/27)%3-1;
			f[j+2][i]=(p/9)%3-1;
			f[j+3][i]=(p/3)%3-1;
			f[j+4][i]=p%3-1;
		}
	}
	dfs(0);
	for(int i=0;i<nh;i++)
	{
		for(int j=0;j<nv;j++)
		{
			hops(i,j,dist[j][i]);
		}
	}
}

Compilation message

encoder.cpp: In function 'void encode(int, int, int, int*, int*)':
encoder.cpp:139:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |   for(int i=0;i<s.size();i++)encode_bit((int)s[i]-'0');
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 15328 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 5 ms 9188 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 10208 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 5 ms 9184 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 33 ms 10464 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 33 ms 10836 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 57 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 30 ms 10552 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 10624 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 34 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 35 ms 10848 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 30 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 64 ms 11104 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 32 ms 10464 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 33 ms 10704 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 11020 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 52 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 69 ms 11232 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 46 ms 10924 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 80 ms 11564 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 90 ms 11616 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 11360 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 90 ms 12084 KB Output is correct - 67950 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 15328 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 5 ms 9188 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 10208 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 5 ms 9184 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 33 ms 10464 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 33 ms 10836 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 57 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 30 ms 10552 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 10624 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 34 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 35 ms 10848 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 30 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 64 ms 11104 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 32 ms 10464 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 33 ms 10704 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 11020 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 52 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 69 ms 11232 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 46 ms 10924 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 80 ms 11564 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 90 ms 11616 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 11360 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 90 ms 12084 KB Output is correct - 67950 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 15328 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 5 ms 9188 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 10208 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 5 ms 9184 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 33 ms 10464 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 33 ms 10836 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 57 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 30 ms 10552 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 10624 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 34 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 35 ms 10848 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 30 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 64 ms 11104 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 32 ms 10464 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 33 ms 10704 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 11020 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 52 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 69 ms 11232 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 46 ms 10924 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 80 ms 11564 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 90 ms 11616 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 11360 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 90 ms 12084 KB Output is correct - 67950 call(s) of encode_bit()
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 15328 KB Output is correct - 67950 call(s) of encode_bit()
2 Correct 5 ms 9188 KB Output is correct - 94 call(s) of encode_bit()
3 Correct 28 ms 10208 KB Output is correct - 61190 call(s) of encode_bit()
4 Correct 5 ms 9184 KB Output is correct - 130 call(s) of encode_bit()
5 Correct 33 ms 10464 KB Output is correct - 61190 call(s) of encode_bit()
6 Correct 33 ms 10836 KB Output is correct - 67950 call(s) of encode_bit()
7 Correct 57 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
8 Correct 30 ms 10552 KB Output is correct - 65256 call(s) of encode_bit()
9 Correct 32 ms 10624 KB Output is correct - 67950 call(s) of encode_bit()
10 Correct 34 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
11 Correct 35 ms 10848 KB Output is correct - 67950 call(s) of encode_bit()
12 Correct 30 ms 10592 KB Output is correct - 67950 call(s) of encode_bit()
13 Correct 64 ms 11104 KB Output is correct - 67950 call(s) of encode_bit()
14 Correct 32 ms 10464 KB Output is correct - 67950 call(s) of encode_bit()
15 Correct 33 ms 10704 KB Output is correct - 67950 call(s) of encode_bit()
16 Correct 60 ms 11020 KB Output is correct - 67950 call(s) of encode_bit()
17 Correct 52 ms 10976 KB Output is correct - 67950 call(s) of encode_bit()
18 Correct 69 ms 11232 KB Output is correct - 67950 call(s) of encode_bit()
19 Correct 46 ms 10924 KB Output is correct - 67950 call(s) of encode_bit()
20 Correct 80 ms 11564 KB Output is correct - 67950 call(s) of encode_bit()
21 Correct 90 ms 11616 KB Output is correct - 67950 call(s) of encode_bit()
22 Correct 60 ms 11360 KB Output is correct - 67950 call(s) of encode_bit()
23 Correct 90 ms 12084 KB Output is correct - 67950 call(s) of encode_bit()