Submission #116966

# Submission time Handle Problem Language Result Execution time Memory
116966 2019-06-14T09:45:04 Z tmwilliamlin168 City (JOI17_city) C++14
97 / 100
734 ms 68824 KB
#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN=2.5e5, B=1<<8;
vector<int> adj[mxN];
int s[mxN], dt1, dt2;

int encrange(int a, int b) {
	return b*(b-1)/2+a;
}

void dfs2(int u) {
	int ds=dt2++;
	for(int v : adj[u])
		dfs2(v);
	Code(u, 1<<28|dt1<<15|encrange(ds, dt2));
}

void dfs1(int u=0, int p=-1, int d=0) {
	int ds=dt1;
	s[u]=1;
	if(~p)
		adj[u].erase(find(adj[u].begin(), adj[u].end(), p));
	for(int v : adj[u]) {
		dfs1(v, u, d+1);
		s[u]+=s[v];
	}
	if(u&&s[u]<B)
		return;
	sort(adj[u].begin(), adj[u].end(), [](const int &a, const int &b) {
		return s[a]<s[b];
	});
	for(int i=0, cs; i<adj[u].size()&&s[adj[u][i]]<B; ++dt1) {
		dt2=0, cs=0;
		while(i<adj[u].size()&&cs+s[adj[u][i]]<B) {
			cs+=s[adj[u][i]];
			dfs2(adj[u][i++]);
		}
	}
	Code(u, d<<23|encrange(ds, dt1));
}

void Encode(int n, int a[], int b[]) {
	for(int i=0; i<n-1; ++i) {
		adj[a[i]].push_back(b[i]);
		adj[b[i]].push_back(a[i]);
	}
	dfs1();
}
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;

void InitDevice() {}

array<int, 2> decrange(int x) {
	int l=1, r=1<<12;
	while(l<r) {
		int m=(l+r+1)/2;
		if(m*(m-1)/2<=x)
			l=m;
		else
			r=m-1;
	}
	return {x-r*(r-1)/2, r};
}

int Answer(long long s, long long t) {
	if(s>>28&&t>>28) {
		if((s>>15^t>>15)&(1<<12)-1)
			return 2;
		array<int, 2> rs=decrange(s&(1<<15)-1), rt=decrange(t&(1<<15)-1);
		if(rs[0]<=rt[0]&&rt[0]<rs[1])
			return 1;
		if(rt[0]<=rs[0]&&rs[0]<rt[1])
			return 0;
		return 2;
	}
	if(s>>28) {
		int x=s>>15&(1<<12)-1;
		array<int, 2> r=decrange(t&(1<<23)-1);
		return r[0]<=x&&x<r[1]?0:2;
	}
	if(t>>28) {
		int x=t>>15&(1<<12)-1;
		array<int, 2> r=decrange(s&(1<<23)-1);
		return r[0]<=x&&x<r[1]?1:2;
	}
	int sd=s>>23, td=t>>23;
	array<int, 2> rs=decrange(s&(1<<23)-1), rt=decrange(t&(1<<23)-1);
	if(td>sd&&rs[0]<=rt[0]&&rt[0]<rs[1])
		return 1;
	if(sd>td&&rt[0]<=rs[0]&&rs[0]<rt[1])
		return 0;
	return 2;
}

Compilation message

Encoder.cpp: In function 'void dfs1(int, int, int)':
Encoder.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0, cs; i<adj[u].size()&&s[adj[u][i]]<B; ++dt1) {
                   ~^~~~~~~~~~~~~~
Encoder.cpp:36:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(i<adj[u].size()&&cs+s[adj[u][i]]<B) {
         ~^~~~~~~~~~~~~~

Device.cpp: In function 'int Answer(long long int, long long int)':
Device.cpp:21:27: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   if((s>>15^t>>15)&(1<<12)-1)
                    ~~~~~~~^~
Device.cpp:23:38: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   array<int, 2> rs=decrange(s&(1<<15)-1), rt=decrange(t&(1<<15)-1);
                               ~~~~~~~^~
Device.cpp:23:64: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   array<int, 2> rs=decrange(s&(1<<15)-1), rt=decrange(t&(1<<15)-1);
                                                         ~~~~~~~^~
Device.cpp:31:22: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   int x=s>>15&(1<<12)-1;
               ~~~~~~~^~
Device.cpp:32:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   array<int, 2> r=decrange(t&(1<<23)-1);
                              ~~~~~~~^~
Device.cpp:36:22: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   int x=t>>15&(1<<12)-1;
               ~~~~~~~^~
Device.cpp:37:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   array<int, 2> r=decrange(s&(1<<23)-1);
                              ~~~~~~~^~
Device.cpp:41:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  array<int, 2> rs=decrange(s&(1<<23)-1), rt=decrange(t&(1<<23)-1);
                              ~~~~~~~^~
Device.cpp:41:63: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  array<int, 2> rs=decrange(s&(1<<23)-1), rt=decrange(t&(1<<23)-1);
                                                        ~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12544 KB Output is correct
2 Correct 9 ms 12288 KB Output is correct
3 Correct 9 ms 12288 KB Output is correct
4 Correct 9 ms 12288 KB Output is correct
5 Correct 8 ms 12288 KB Output is correct
6 Correct 8 ms 12288 KB Output is correct
7 Correct 9 ms 12288 KB Output is correct
8 Correct 9 ms 12544 KB Output is correct
9 Correct 11 ms 12288 KB Output is correct
10 Correct 9 ms 12544 KB Output is correct
11 Correct 9 ms 12288 KB Output is correct
12 Correct 9 ms 12544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 206 ms 26472 KB Output is partially correct - L = 268544637
2 Partially correct 177 ms 26352 KB Output is partially correct - L = 268599620
3 Partially correct 172 ms 26608 KB Output is partially correct - L = 268610173
4 Partially correct 173 ms 26352 KB Output is partially correct - L = 268533631
5 Partially correct 522 ms 66864 KB Output is partially correct - L = 321403768
6 Partially correct 520 ms 67104 KB Output is partially correct - L = 320596604
7 Partially correct 500 ms 67056 KB Output is partially correct - L = 321569588
8 Partially correct 517 ms 66544 KB Output is partially correct - L = 300449663
9 Partially correct 451 ms 68304 KB Output is partially correct - L = 302645119
10 Partially correct 455 ms 68824 KB Output is partially correct - L = 300984232
11 Partially correct 471 ms 68568 KB Output is partially correct - L = 301039616
12 Partially correct 464 ms 68304 KB Output is partially correct - L = 300974080
13 Partially correct 478 ms 67760 KB Output is partially correct - L = 309910846
14 Partially correct 524 ms 66944 KB Output is partially correct - L = 316310364
15 Partially correct 172 ms 26352 KB Output is partially correct - L = 268572305
16 Partially correct 190 ms 26352 KB Output is partially correct - L = 268600948
17 Partially correct 173 ms 26352 KB Output is partially correct - L = 268548124
18 Partially correct 519 ms 67184 KB Output is partially correct - L = 301039621
19 Partially correct 522 ms 67240 KB Output is partially correct - L = 300711936
20 Partially correct 496 ms 67208 KB Output is partially correct - L = 300680202
21 Partially correct 489 ms 67296 KB Output is partially correct - L = 301694996
22 Partially correct 575 ms 67040 KB Output is partially correct - L = 300646405
23 Partially correct 590 ms 66960 KB Output is partially correct - L = 300627827
24 Partially correct 624 ms 66928 KB Output is partially correct - L = 300810275
25 Partially correct 633 ms 67056 KB Output is partially correct - L = 300716495
26 Partially correct 734 ms 67056 KB Output is partially correct - L = 300825464
27 Partially correct 610 ms 66912 KB Output is partially correct - L = 301041211