# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
427268 |
2021-06-14T13:52:05 Z |
tqbfjotld |
City (JOI17_city) |
C++14 |
|
1174 ms |
59724 KB |
#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;
int lch[500005];
int rch[500005];
int curnodes,n;
vector<int> adjl[250005];
double const1 = 0.9;
double const2 = 1.0;
double func(int node, int pa){
set<pair<double,int> > stuff;
for (auto x : adjl[node]){
if (x==pa) continue;
double res = func(x,node);
stuff.insert({res,x});
}
while (stuff.size()>2){
auto i1 = *stuff.begin();
stuff.erase(stuff.begin());
pair<double,int> thing = {-999.0,-1};
auto it = stuff.lower_bound({i1.first+const1,-1});
if (it!=stuff.end()){
thing = (*it);
}
if (it!=stuff.begin()){
it--;
if (abs(thing.first-(i1.first+const1))>abs((*it).first-(i1.first+const1))){
thing = *it;
}
}
auto i2 = thing;
stuff.erase(stuff.lower_bound(thing));
int nw = curnodes++;
lch[nw] = i2.second;
rch[nw] = i1.second;
stuff.insert({max(i2.first+const2,i1.first+const1+const2),nw});
}
if (stuff.size()==2){
auto i1 = *stuff.begin();
stuff.erase(stuff.begin());
auto i2 = *stuff.begin();
stuff.erase(stuff.begin());
lch[node] = i2.second;
rch[node] = i1.second;
return max(i2.first+const2,i1.first+const1+const2);
}
if (stuff.size()==1){
auto i1 = *stuff.begin();
lch[node] = i1.second;
return i1.first+const2;
}
return 0.0;
}
void dfs2(int node, long long curamt, int pos){
//printf("ch of %d = %d %d\n",node,lch[node],rch[node]);
if (node<n){
// printf("code %d %lld\n",node,curamt+(1LL<<pos));
Code(node,curamt+(1LL<<pos));
}
if (lch[node]!=-1){
if (lch[node]<n) Code(lch[node],curamt+(5LL<<pos));
if (lch[lch[node]]!=-1){
dfs2(lch[lch[node]],curamt,pos+1);
}
if (rch[lch[node]]!=-1){
dfs2(rch[lch[node]],curamt+(1LL<<pos),pos+3);
}
}
if (rch[node]!=-1){
if (rch[node]<n) Code(rch[node],curamt+(7LL<<pos));
if (lch[rch[node]]!=-1){
dfs2(lch[rch[node]],curamt+(3LL<<pos),pos+3);
}
if (rch[rch[node]]!=-1){
dfs2(rch[rch[node]],curamt+(7LL<<pos),pos+3);
}
}
}
void Encode(int N, int A[], int B[])
{
n = N;
memset(lch,-1,sizeof(lch));
memset(rch,-1,sizeof(rch));
curnodes = N;
for (int x = 0; x<N-1; x++){
adjl[A[x]].push_back(B[x]);
adjl[B[x]].push_back(A[x]);
}
func(0,-1);
dfs2(0,0,0);
}
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;
void InitDevice()
{
}
int Answer(long long S, long long T)
{
string s1,s2;
for (int x = 0; x<64; x++){
if (S)s1.push_back((S&1)?'1':'0');
S>>=1;
if (T)s2.push_back((T&1)?'1':'0');
T>>=1;
}
s1.pop_back();
s2.pop_back();
for (int x = 0; x<min(s1.size(),s2.size());){
if (s1[x]=='0'){
if (s2[x]=='0') {
x++; continue;
}
if (s2[x+1]=='0'){
if (s2.size()==x+2){
return 0;
}
}
return 2;
}
else if (s2[x]=='0'){
if (s1[x+1]=='0'){
if (s1.size()==x+2){
return 1;
}
}
return 2;
}
else if (min(s1.size(),s2.size())==x+2){
if (s1[x]==s2[x] && s1[x+1]==s2[x+1]) {
x+=2;
continue;
}
else{
return 2;
}
}
else{
if (s1[x]==s2[x] && s1[x+1]==s2[x+1] && s1[x+2]==s2[x+2]){
x+=3;
continue;
}
return 2;
}
}
//printf("cmp %s %s\n",s1.c_str(),s2.c_str());
return s1.size()<s2.size()?1:0;
if (s1.size()<s2.size()){
for (int x = 0; x<s1.size(); x++){
if (s1[x]!=s2[x]) return 2;
}
return 1;
}
for (int x = 0; x<s2.size(); x++){
if (s1[x]!=s2[x]) return 2;
}
return 0;
}
Compilation message
Device.cpp: In function 'int Answer(long long int, long long int)':
Device.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
20 | for (int x = 0; x<min(s1.size(),s2.size());){
| ~^~~~~~~~~~~~~~~~~~~~~~~~~
Device.cpp:26:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
26 | if (s2.size()==x+2){
| ~~~~~~~~~^~~~~
Device.cpp:34:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
34 | if (s1.size()==x+2){
| ~~~~~~~~~^~~~~
Device.cpp:40:42: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
40 | else if (min(s1.size(),s2.size())==x+2){
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
Device.cpp:60:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int x = 0; x<s1.size(); x++){
| ~^~~~~~~~~~
Device.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int x = 0; x<s2.size(); x++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10372 KB |
Output is correct |
2 |
Correct |
7 ms |
10372 KB |
Output is correct |
3 |
Correct |
7 ms |
10376 KB |
Output is correct |
4 |
Correct |
7 ms |
10332 KB |
Output is correct |
5 |
Correct |
8 ms |
10348 KB |
Output is correct |
6 |
Correct |
8 ms |
10328 KB |
Output is correct |
7 |
Correct |
8 ms |
10372 KB |
Output is correct |
8 |
Correct |
7 ms |
10376 KB |
Output is correct |
9 |
Correct |
7 ms |
10372 KB |
Output is correct |
10 |
Correct |
8 ms |
10500 KB |
Output is correct |
11 |
Correct |
6 ms |
10372 KB |
Output is correct |
12 |
Correct |
8 ms |
10460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
283 ms |
21448 KB |
Output is correct - L = 44470 |
2 |
Correct |
277 ms |
21464 KB |
Output is correct - L = 355510 |
3 |
Correct |
277 ms |
21416 KB |
Output is correct - L = 58770 |
4 |
Correct |
254 ms |
21388 KB |
Output is correct - L = 32457 |
5 |
Partially correct |
634 ms |
46308 KB |
Output is partially correct - L = 2992319707 |
6 |
Partially correct |
673 ms |
43392 KB |
Output is partially correct - L = 12002375259 |
7 |
Partially correct |
737 ms |
43440 KB |
Output is partially correct - L = 2912340377 |
8 |
Correct |
661 ms |
43064 KB |
Output is correct - L = 134217723 |
9 |
Partially correct |
1111 ms |
57992 KB |
Output is partially correct - L = 68719476224 |
10 |
Partially correct |
1111 ms |
59556 KB |
Output is partially correct - L = 68719476224 |
11 |
Partially correct |
1174 ms |
59704 KB |
Output is partially correct - L = 68719476224 |
12 |
Partially correct |
1133 ms |
59724 KB |
Output is partially correct - L = 68719476224 |
13 |
Partially correct |
955 ms |
51504 KB |
Output is partially correct - L = 34359736576 |
14 |
Partially correct |
786 ms |
46856 KB |
Output is partially correct - L = 8589934080 |
15 |
Correct |
298 ms |
21404 KB |
Output is correct - L = 234201 |
16 |
Correct |
289 ms |
21280 KB |
Output is correct - L = 353865 |
17 |
Correct |
318 ms |
21448 KB |
Output is correct - L = 63049 |
18 |
Partially correct |
844 ms |
50924 KB |
Output is partially correct - L = 66571991296 |
19 |
Partially correct |
899 ms |
51412 KB |
Output is partially correct - L = 64424505856 |
20 |
Partially correct |
909 ms |
51440 KB |
Output is partially correct - L = 64424505856 |
21 |
Partially correct |
829 ms |
48760 KB |
Output is partially correct - L = 68182577408 |
22 |
Partially correct |
916 ms |
49596 KB |
Output is partially correct - L = 103079208064 |
23 |
Partially correct |
790 ms |
46720 KB |
Output is partially correct - L = 103079208064 |
24 |
Partially correct |
814 ms |
48056 KB |
Output is partially correct - L = 94489273728 |
25 |
Partially correct |
811 ms |
45844 KB |
Output is partially correct - L = 25769796992 |
26 |
Partially correct |
901 ms |
45884 KB |
Output is partially correct - L = 23621526912 |
27 |
Partially correct |
756 ms |
45344 KB |
Output is partially correct - L = 11811153280 |