提出 #25705814
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
#define N 2003
#define int long long
#define F(i,l,r) for(int i=l;i<=r;++i)
#define D(i,r,l) for(int i=r;i>=l;--i)
#define Fs(i,l,r,c) for(int i=l;i<=r;c)
#define Ds(i,r,l,c) for(int i=r;i>=l;c)
#define MEM(x,a) memset(x,a,sizeof(x))
#define FK(x) MEM(x,0)
#define Tra(i,u) for(int i=G.h[u],v=G.to(i);~i;i=G.nx(i),v=G.to(i))
#define p_b push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define iter(a,p) (a.begin()+p)
#define PUT(a,n) F(i,1,n) printf("%d ",a[i]); puts("");
int I() {char c=getchar(); int x=0; int f=1; while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return ((f==1)?x:-x);}
template <typename T> void Rd(T& arg){arg=I();}
template <typename T,typename...Types> void Rd(T& arg,Types&...args){arg=I(); Rd(args...);}
void RA(int *p,int n) {F(i,1,n) *p=I(),++p;}
int f[N][N],pre[N][N];
void Init()
{
int n=2000;
MEM(f,0x3f);
f[0][0]=0;
f[1][0]=f[0][1]=1;
pre[0][1]=2; pre[1][0]=1;
F(i,1,n) F(j,1,n)
{
if (f[i][j-1]+1<f[i-1][j]+1)
{
f[i][j]=f[i][j-1]+1;
pre[i][j]=2;
}
else
{
f[i][j]=f[i-1][j]+1;
pre[i][j]=1;
}
if (i<=j)
{
if (f[i][j-i]+1<f[i][j])
{
f[i][j]=f[i][j-i]+1;
pre[i][j]=4;
}
}
if (j<=i)
{
if (f[i-j][j]+1<f[i][j])
{
f[i][j]=f[i-j][j]+1;
pre[i][j]=3;
}
}
}
}
int n;
void Input()
{
n=I();
}
int calc(int a,int b)
{
if (b==0) return a;
if (a<=2000) return f[a][b];
return a/b+calc(b,a%b);
}
int ans=1e18,reca;
void up(int a)
{
int tmp=calc(n,a);
if (tmp<ans)
{
ans=tmp;
reca=a;
}
}
vector<int> op;
void path0(int a,int b)
{
// printf("path0 %lld,%lld pre=%lld\n",a,b,pre[a][b]);
if (a==0 and b==0) return;
if (pre[a][b]==1) path0(a-1,b);
if (pre[a][b]==2) path0(a,b-1);
if (pre[a][b]==3) path0(a-b,b);
if (pre[a][b]==4) path0(a,b-a);
op.p_b(pre[a][b]);
}
void path(int a,int b,bool f) // f=0:凑a,b; f=1:凑b,a
{
// printf("path %lld,%lld f=%d\n",a,b,f);
if (b==0)
{
if (f==0) F(i,1,a) op.p_b(1);
else F(i,1,a) op.p_b(2);
return;
}
if (a<=2000)
{
if (f==0) return path0(a,b);
else return path0(b,a);
}
path(b,a%b,f^1);
if (f==0) {F(i,1,a/b) op.p_b(3);}
else {F(i,1,a/b) op.p_b(4);}
}
int r10(){return rand()%1024;}
int rnd64()
{
return (r10()<<30)|(r10()<<40)|(r10()<<50)|(r10()<<20)|r10();
}
void Sakuya()
{
srand(time(0));
int u=rnd64()%n+1,x;
for(double ra=0.45;ra<=0.65;ra+=0.001) up(n*ra),up(n*(1-ra));
x=n/2; F(i,1,1000000) {x=x%n+1; up(x);}
x=n/2; F(i,1,1000000) {x=(x+n-2)%n+1; up(x);}
int seed=(n<=1e11?19260817:100000000003ll);
x=u; F(i,1,1000000) {x=(x+seed+r10())%n+1; up(x);}
F(i,1,200000) {x=rnd64()%n+1; up(x);}
// up(556914163161803996);
printf("%lld\n",ans);
// printf("reca=%lld\n",reca);
path(n,reca,0);
assert((int) op.size() == ans);
for(auto x:op) printf("%lld\n",x); puts("");
}
void IsMyWife()
{
Init();
Input();
Sakuya();
}
}
#undef int //long long
int main()
{
Flandre_Scarlet::IsMyWife();
getchar();
return 0;
}
提出情報
提出日時
2021-09-09 20:14:37+0900
問題
C - Calculator
ユーザ
LightningUZ
言語
C++ (GCC 9.2.1)
得点
600
コード長
3758 Byte
結果
AC
実行時間
761 ms
メモリ
66432 KiB
コンパイルエラー
./Main.cpp: In function ‘void Flandre_Scarlet::Sakuya()’:
./Main.cpp:132:6: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
132 | for(auto x:op) printf("%lld\n",x); puts("");
| ^~~
./Main.cpp:132:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
132 | for(auto x:op) printf("%lld\n",x); puts("");
| ^~~~
ジャッジ結果
セット名
Sample
All
得点 / 配点
0 / 0
600 / 600
結果
セット名
テストケース
Sample
00-sample-001.txt
All
00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt
ケース名
結果
実行時間
メモリ
00-sample-001.txt
AC
128 ms
66356 KiB
01-001.txt
AC
121 ms
66316 KiB
01-002.txt
AC
123 ms
66356 KiB
01-003.txt
AC
124 ms
66176 KiB
01-004.txt
AC
748 ms
66256 KiB
01-005.txt
AC
756 ms
66428 KiB
01-006.txt
AC
747 ms
66432 KiB
01-007.txt
AC
727 ms
66420 KiB
01-008.txt
AC
701 ms
66200 KiB
01-009.txt
AC
723 ms
66360 KiB
01-010.txt
AC
731 ms
66180 KiB
01-011.txt
AC
728 ms
66256 KiB
01-012.txt
AC
737 ms
66420 KiB
01-013.txt
AC
740 ms
66360 KiB
01-014.txt
AC
749 ms
66316 KiB
01-015.txt
AC
761 ms
66284 KiB
01-016.txt
AC
746 ms
66176 KiB
01-017.txt
AC
730 ms
66360 KiB
01-018.txt
AC
729 ms
66432 KiB
01-019.txt
AC
729 ms
66252 KiB
01-020.txt
AC
740 ms
66324 KiB
01-021.txt
AC
741 ms
66200 KiB
01-022.txt
AC
750 ms
66204 KiB
01-023.txt
AC
743 ms
66236 KiB
01-024.txt
AC
754 ms
66252 KiB
01-025.txt
AC
742 ms
66228 KiB