#include <bits/stdc++.h>
using namespace std;
vector<pair<long long,long long> >vps;
int cntdpth=1;
string maxx(string b1,string b2){
if(b1.size()>b2.size())
return b1;
if(b1.size()<b2.size())
return b2;
for(int i=0;i<b1.size();i++){
if(b1[i]>b2[i])
return b1;
if(b1[i]<b2[i])
return b2;
}
return b1;
}
string trg;
string slvmx(int cr=0,int dpth=1){
cntdpth=max(cntdpth,dpth);
string mx="0";
if(vps[cr].first<=0){
string binary = std::bitset<32>(vps[cr].first*-1ll).to_string(); //"00000000000000000000000010000000"
binary.erase(0, binary.find_first_not_of('0')); //"10000000"
if(binary.size()==0)
binary+='0';
mx=maxx(mx,binary);
}else{
string ret=slvmx(vps[cr].first-1,dpth+1);
if(ret!="0")
ret+='0';
mx=maxx(mx,ret);
}
if(vps[cr].second<=0){
string binary = std::bitset<32>(vps[cr].second*-1ll).to_string(); //"00000000000000000000000010000000"
binary.erase(0, binary.find_first_not_of('0')); //"10000000"
if(binary.size()==0)
binary+='0';
mx=maxx(mx,binary);
}else{
string ret=slvmx(vps[cr].second-1,dpth+1);
if(ret!="0")
ret+='0';
mx=maxx(mx,ret);
}
return mx;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin>>n;
vps=vector<pair<long long,long long> >(n);
for(int i=0;i<n;i++){
long long x,y;
cin>>x>>y;
vps[i]={x,y};
}
trg=slvmx();
trg+='0';
int f=0;
int i=trg.size()-1;
for(;i>trg.size()-1-cntdpth;i--){
if(trg[i]=='1'){
f=1;
trg[i]='0';
}
}
while(f&&i>=0){
if(trg[i]=='0'){
trg[i]='1';
break;
}else{
trg[i]='0';
}
i--;
}
i=0;
for(;i<trg.size()-1&&trg[i]=='0';i++);
for(;i<trg.size();i++)cout << trg[i];
return 0;
}
/***
3 5 4
1 2 4 2 1
3 5 1 2 4
1 5 7 1 2
*/
Compilation message
poklon.cpp: In function 'std::string maxx(std::string, std::string)':
poklon.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i=0;i<b1.size();i++){
| ~^~~~~~~~~~
poklon.cpp: In function 'int main()':
poklon.cpp:69:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(;i>trg.size()-1-cntdpth;i--){
| ~^~~~~~~~~~~~~~~~~~~~~
poklon.cpp:88:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(;i<trg.size()-1&&trg[i]=='0';i++);
| ~^~~~~~~~~~~~~
poklon.cpp:89:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(;i<trg.size();i++)cout << trg[i];
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
12 ms |
2176 KB |
Output is correct |
12 |
Correct |
13 ms |
1920 KB |
Output is correct |
13 |
Correct |
86 ms |
10104 KB |
Output is correct |
14 |
Correct |
299 ms |
20348 KB |
Output is correct |
15 |
Correct |
77 ms |
3192 KB |
Output is correct |
16 |
Execution timed out |
1087 ms |
48376 KB |
Time limit exceeded |
17 |
Execution timed out |
1096 ms |
100600 KB |
Time limit exceeded |
18 |
Execution timed out |
1102 ms |
115192 KB |
Time limit exceeded |
19 |
Execution timed out |
1098 ms |
78868 KB |
Time limit exceeded |
20 |
Runtime error |
363 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |