| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 42384 | wasyl | Poklon (COCI17_poklon7) | C++11 | 1086 ms | 99952 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#define d(...) __VA_ARGS__
#define EB(...) emplace_back(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template< typename t >
using V = vector< t >;
struct BinNum
{
string n;
int ile_zer = 0;
BinNum( ll v )
{
while ( v > 0 )
{
n += string( 1, ( v % 2 ) + '0' );
v /= 2;
}
reverse( n.begin(), n.end() );
}
BinNum() : n( string() ) {}
BinNum( const BinNum& a )
{
n = a.n;
ile_zer = a.ile_zer;
}
inline bool operator< ( BinNum&& a )
{
if ( a.n.size() + a.ile_zer == (*this).n.size() + (*this).ile_zer )
{
if ( (*this).n.size() < a.n.size() )
{
(*this).ile_zer -= a.n.size() - (*this).n.size();
(*this).n.resize( a.n.size(), '0' );
}
if ( a.n.size() < (*this).n.size() )
{
a.ile_zer -= (*this).n.size() - a.n.size();
a.n.resize( (*this).n.size(), '0' );
}
for ( int i = 0; i < a.n.size(); ++i )
if ( a.n[i] != (*this).n[i] )
return (*this).n[i] < a.n[i];
return false;
}
return (*this).n.size() + (*this).ile_zer < a.n.size() + a.ile_zer;
}
inline bool operator< ( BinNum& a )
{
if ( a.n.size() + a.ile_zer == (*this).n.size() + (*this).ile_zer )
{
if ( (*this).n.size() < a.n.size() )
{
(*this).ile_zer -= a.n.size() - (*this).n.size();
(*this).n.resize( a.n.size(), '0' );
}
if ( a.n.size() < (*this).n.size() )
{
a.ile_zer -= (*this).n.size() - a.n.size();
a.n.resize( (*this).n.size(), '0' );
}
for ( int i = 0; i < a.n.size(); ++i )
if ( a.n[i] != (*this).n[i] )
return (*this).n[i] < a.n[i];
return false;
}
return (*this).n.size() + (*this).ile_zer < a.n.size() + a.ile_zer;
}
inline void operator <<= ( int poz )
{
(*this).ile_zer += poz;
}
};
inline ostream& operator<< ( ostream& s, const BinNum& a )
{
return s << a.n << string( a.ile_zer, '0' );
}
struct Node
{
int l = -1, p = -1;
BinNum sum;
};
int n;
V< Node > graf;
void dfs ( int v )
{
for ( int s : { graf[v].l, graf[v].p } )
if ( s != -1 )
{
dfs( s );
if ( graf[v].sum < graf[s].sum )
graf[v].sum = graf[s].sum;
}
graf[v].sum <<= 1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
graf.resize( n + 1 );
for ( int i = 1; i <= n; ++i )
{
int p, p2; cin >> p >> p2;
if ( p < 0 )
{
if ( graf[i].sum < BinNum( -p ) )
graf[i].sum = BinNum( -p );
}
else
graf[i].l = p;
if ( p2 < 0 )
{
if ( graf[i].sum < BinNum( -p2 ) )
graf[i].sum = BinNum( -p2 );
}
else
graf[i].p = p2;
}
dfs( 1 );
cout << graf[1].sum << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
