# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
795835 |
2023-07-27T17:16:17 Z |
Antekb |
Flights (JOI22_flights) |
C++17 |
|
229 ms |
2204 KB |
#include "Ali.h"
#include <string>
#include <vector>
#include<cassert>
#include<iostream>
#define pb push_back
using namespace std;
namespace {
vector<int> dep, tab, gdzie;
vector<vector<int> > E;
int blo_siz=14;
int blo_num=1440;
int max_pot=14;
string enc(int a){
string res(max_pot, '0');
for(int i=0; i<max_pot; i++){
res[i]='0'+!!(a&(1<<i));
}
return res;
}
int dec(string s){
int res=0;
for(int i=0; i<s.size(); i++){
res+=(1<<i)*(s[i]-'0');
}
return res;
}
pair<int, int> dec2(int x){
//cerr<<x<<" ";
for(int i=0; i<blo_num; i++){
if(x<blo_num-i){
//cerr<<i<<" "<<x<<"\n";
return {i, i+x};
}
else x-=blo_num-i;
}
assert(false);
}
}
void dfs(int v, int p){
//cerr<<v<<" "<<p<<endl;
gdzie[v]=tab.size();
tab.pb(dep[v]);
for(int u:E[v]){
if(u!=p){
dep[u]=dep[v]+1;
dfs(u, v);
tab.pb(dep[v]);
}
}
}
void Init(int n, std::vector<int> U, std::vector<int> V) {
E.clear();
gdzie.clear();
dep.clear();
tab.clear();
gdzie.resize(n);
dep.resize(n);
E.resize(n);
for(int i=0; i<n-1; i++){
//cerr<<U[i]<<" "<<V[i]<<endl;
E[U[i]].pb(V[i]);
E[V[i]].pb(U[i]);
}
dfs(0, -1);
for(int i=0; i<n; i++){
SetID(i, gdzie[i]);
}
while(tab.size()%blo_siz){
tab.pb(tab.back()+1);
}
}
string SendA(std::string s) {
pair<int, int> x=dec2(dec(s));
int b1=x.first, b2=x.second;
int mini=(1<<max_pot)-1;
string res;
for(int i=b1+1; i<b2; i++){
for(int j=i*blo_siz; j<(i+1)*blo_siz; j++){
mini=min(mini, tab[j]);
}
}
res+=enc(mini);
res+=enc(tab[b1*blo_siz]);
for(int i=b1*blo_siz+1; i<blo_siz*(b1+1); i++){
res+='0'+char(tab[i]>tab[i-1]);
}
res+=enc(tab[b2*blo_siz]);
for(int i=b2*blo_siz+1; i<blo_siz*(b2+1); i++){
res+='0'+char(tab[i]>tab[i-1]);
}
return res;
}
#include "Benjamin.h"
#include <string>
#include <vector>
#include<cassert>
#include<iostream>
using namespace std;
namespace {
int blo_siz=14;
int blo_num=1440;
int max_pot=14;
int X, Y;
string enc(int a){
string res(20, '0');
for(int i=0; i<20; i++){
res[i]='0'+!!(a&(1<<i));
}
return res;
}
int dec(string s){
//cerr<<s<<"\n";
int res=0;
for(int i=0; i<s.size(); i++){
res+=(1<<i)*(s[i]-'0');
}
return res;
}
int enc2(int a, int b){
//cerr<<a<<" "<<b<<" ";
int r=0;
for(int i=0; i<a; i++){
r+=blo_num-i;
}
r+=b-a;
//cerr<<r<<"\n";
return r;
}
}
string SendB(int N, int _X, int _Y) {
X=_X;
Y=_Y;
if(X>Y)swap(X, Y);
return enc(enc2(X/blo_siz, Y/blo_siz));
}
int Answer(string s) {
int mini=dec(s.substr(0, max_pot));
vector<int> blo1(blo_siz), blo2(blo_siz);
blo1[0]=dec(s.substr(max_pot, max_pot));
for(int i=1; i<blo_siz;i++){
if(s[max_pot*2-1+i]=='1')blo1[i]=blo1[i-1]+1;
else blo1[i]=blo1[i-1]-1;
}
blo2[0]=dec(s.substr(2*max_pot+blo_siz-1, max_pot));
for(int i=1; i<blo_siz;i++){
if(s[max_pot*3+blo_siz-2+i]=='1')blo2[i]=blo2[i-1]+1;
else blo2[i]=blo2[i-1]-1;
}
int ans=blo1[X%blo_siz]+blo2[Y%blo_siz];
if(X/blo_siz!=Y/blo_siz){
for(int i=X%blo_siz;i<blo_siz; i++){
mini=min(mini, blo1[i]);
}
for(int i=Y%blo_siz;i>=0; i--){
mini=min(mini, blo2[i]);
}
}
else{
for(int i=X%blo_siz;i<=Y%blo_siz; i++){
mini=min(mini, blo1[i]);
}
}
return ans-2*mini;
}
Compilation message
Ali.cpp: In function 'int {anonymous}::dec(std::string)':
Ali.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
grader_ali.cpp:10:8: warning: '{anonymous}::_randmem' defined but not used [-Wunused-variable]
10 | char _randmem[12379];
| ^~~~~~~~
Benjamin.cpp: In function 'int {anonymous}::dec(std::string)':
Benjamin.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Correct |
0 ms |
400 KB |
Output is correct |
3 |
Correct |
1 ms |
400 KB |
Output is correct |
4 |
Correct |
1 ms |
400 KB |
Output is correct |
5 |
Correct |
2 ms |
400 KB |
Output is correct |
6 |
Correct |
4 ms |
1636 KB |
Output is correct |
7 |
Correct |
4 ms |
1544 KB |
Output is correct |
8 |
Correct |
6 ms |
1424 KB |
Output is correct |
9 |
Correct |
4 ms |
1424 KB |
Output is correct |
10 |
Correct |
6 ms |
1768 KB |
Output is correct |
11 |
Correct |
4 ms |
1352 KB |
Output is correct |
12 |
Correct |
6 ms |
1632 KB |
Output is correct |
13 |
Correct |
5 ms |
1424 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
5 ms |
2064 KB |
Output is correct |
16 |
Correct |
5 ms |
1552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
400 KB |
Output is partially correct |
2 |
Partially correct |
45 ms |
2148 KB |
Output is partially correct |
3 |
Partially correct |
3 ms |
528 KB |
Output is partially correct |
4 |
Partially correct |
182 ms |
1692 KB |
Output is partially correct |
5 |
Partially correct |
181 ms |
1604 KB |
Output is partially correct |
6 |
Partially correct |
207 ms |
1524 KB |
Output is partially correct |
7 |
Partially correct |
190 ms |
2204 KB |
Output is partially correct |
8 |
Partially correct |
208 ms |
1648 KB |
Output is partially correct |
9 |
Partially correct |
167 ms |
1912 KB |
Output is partially correct |
10 |
Partially correct |
184 ms |
1912 KB |
Output is partially correct |
11 |
Partially correct |
174 ms |
1544 KB |
Output is partially correct |
12 |
Partially correct |
22 ms |
1412 KB |
Output is partially correct |
13 |
Partially correct |
106 ms |
1548 KB |
Output is partially correct |
14 |
Partially correct |
108 ms |
1544 KB |
Output is partially correct |
15 |
Partially correct |
4 ms |
528 KB |
Output is partially correct |
16 |
Partially correct |
206 ms |
2148 KB |
Output is partially correct |
17 |
Partially correct |
165 ms |
2180 KB |
Output is partially correct |
18 |
Partially correct |
191 ms |
1992 KB |
Output is partially correct |
19 |
Partially correct |
168 ms |
2084 KB |
Output is partially correct |
20 |
Partially correct |
121 ms |
1864 KB |
Output is partially correct |
21 |
Partially correct |
158 ms |
1972 KB |
Output is partially correct |
22 |
Partially correct |
197 ms |
1588 KB |
Output is partially correct |
23 |
Partially correct |
159 ms |
1676 KB |
Output is partially correct |
24 |
Partially correct |
192 ms |
1708 KB |
Output is partially correct |
25 |
Partially correct |
166 ms |
1636 KB |
Output is partially correct |
26 |
Partially correct |
162 ms |
1548 KB |
Output is partially correct |
27 |
Partially correct |
171 ms |
1656 KB |
Output is partially correct |
28 |
Partially correct |
161 ms |
1556 KB |
Output is partially correct |
29 |
Partially correct |
191 ms |
1872 KB |
Output is partially correct |
30 |
Partially correct |
158 ms |
1560 KB |
Output is partially correct |
31 |
Partially correct |
179 ms |
1644 KB |
Output is partially correct |
32 |
Partially correct |
229 ms |
1560 KB |
Output is partially correct |
33 |
Partially correct |
180 ms |
1548 KB |
Output is partially correct |
34 |
Partially correct |
184 ms |
1720 KB |
Output is partially correct |
35 |
Partially correct |
199 ms |
1568 KB |
Output is partially correct |
36 |
Partially correct |
160 ms |
1564 KB |
Output is partially correct |
37 |
Partially correct |
185 ms |
1608 KB |
Output is partially correct |
38 |
Partially correct |
170 ms |
1564 KB |
Output is partially correct |
39 |
Partially correct |
26 ms |
1540 KB |
Output is partially correct |
40 |
Partially correct |
195 ms |
2128 KB |
Output is partially correct |