結果
| 問題 |
No.873 バイナリ、ヤバいなり!w
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-01 05:59:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 156 ms / 2,000 ms |
| コード長 | 853 bytes |
| コンパイル時間 | 634 ms |
| コンパイル使用メモリ | 72,480 KB |
| 実行使用メモリ | 7,624 KB |
| 最終ジャッジ日時 | 2024-06-11 14:03:34 |
| 合計ジャッジ時間 | 2,962 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int>A[2];
int dp[3<<17];
int L[3<<17],R[3<<17];
main()
{
cin>>N;
dp[0]=0;
for(int i=1;i<=N;i++)
{
dp[i]=1e9;
L[i]=-1;
R[i]=-1;
}
for(int i=0;i<N;i++)
{
for(int j=1;i+j*j<=N;j++)
{
if(dp[i+j*j]>dp[i]+j)
{
dp[i+j*j]=dp[i]+j;
L[i+j*j]=R[i+j*j]=j;
}
else if(dp[i+j*j]==dp[i]+j)
{
int u=i+j*j;
if(L[u]%2!=j%2)
{
if(j%2)L[u]=j;
}
else
{
if(j%2)L[u]=min(L[u],j);
else L[u]=max(L[u],j);
}
if(R[u]%2!=j%2)
{
if(j%2==0)R[u]=j;
}
else
{
if(j%2)R[u]=max(R[u],j);
else R[u]=min(R[u],j);
}
}
}
}
char c='0';
while(N)
{
int id;
if(c=='0')id=L[N];
else id=R[N];
N-=id*id;
cout<<c;
for(int i=2;i<=id;i++)cout<<(c^=1);
}
cout<<endl;
}