QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462521#1253. Abstract Circular CoverZSH_ZSHTL 0ms3860kbC++141.8kb2024-07-03 20:33:492024-07-03 20:33:50

Judging History

你现在查看的是最新测评结果

  • [2024-07-03 20:33:50]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3860kb
  • [2024-07-03 20:33:49]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define drep(i,a,b) for (int i=(a);i>=(b);i--)
using namespace std;
typedef long long ll;

const int inf=1e9;
inline bool chkmin(int &x,int y)
{
	return (x>y?x=y,1:0);
}

mt19937 rng(3068863558);
inline int rnd(int l,int r){return l+(rng()%(r-l+1));}

int main()
{
	clock_t clk=clock();
	ios::sync_with_stdio(false); cin.tie(0);

	int n; cin>>n;
	// int n=850;
	vector<vector<int> > a(n,vector<int>(n));
	rep(i,0,n-1) rep(j,0,n-1) cin>>a[i][j];
	// rep(i,0,n-1) rep(j,0,n-1) a[i][j]=rnd(1,100000);

	auto norm=[&](int x){return (x+100*n)%n;};

	vector<int> freq(n);
	vector<int> ans(n+1,inf);
	vector<int> mx(n);
	vector<vector<int> > f(n,vector<int>(n+1,inf));
	vector<vector<int> > pre(n,vector<int>(n+1,-1));

	auto solve=[&](int st,int top)
	{
		if (mx[st]>top) return;
		mx[st]=top;

		rep(i,0,n-1) rep(j,0,top) f[i][j]=inf;
		rep(i,0,n-1)
		{
			f[i][1]=a[norm(st)][i];
			pre[i][1]=-1;
			if (i!=n-1)
			{
				rep(j,1,top-1) if (f[i][j]<inf)
				{
					rep(k,i+1,n-1)
					{
						if (chkmin(f[k][j+1],f[i][j]+a[norm(st+i+1)][k-(i+1)]))
						{
							pre[k][j+1]=i;
						}
					}
				}
			}
		}

		rep(i,1,top)
		{
			int now=n-1;
			drep(j,i,1)
			{
				freq[norm(now+1)]++;
				now=pre[now][j];
			}
			chkmin(ans[i],f[n-1][i]);
		}
	};

	vector<int> ord(n);
	rep(i,0,n-1) ord[i]=i;

	drep(k,n,1)
	{
		if (k!=n&&((n/k)==(n/(k+1)))&&rnd(0,22)!=0) continue;
		rep(i,0,n-1) freq[i]=0;
		shuffle(ord.begin(),ord.end(),rng);
		int t=min(n,n/k/5+2);
		rep(i,0,t-1) solve(ord[i],k);

		// sort(ord.begin(),ord.end(),[&](auto x,auto y){return freq[x]>freq[y];});
		// rep(i,0,t-1) solve(ord[i],k);
	}

	rep(i,1,n) printf("%d ",ans[i]);
	printf("\n");

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3860kb

input:

3
10 12 23
7 4 11
8 5 3

output:

3 12 25 

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

1
15

output:

15 

result:

ok "15"

Test #3:

score: -100
Time Limit Exceeded

input:

850
467844 492130 605609 643857 26979 997775 457911 823516 154840 985025 993710 334965 480280 45505 851380 765414 512285 661374 745909 563360 878563 887945 542943 288759 124012 159576 828454 705380 24125 806150 695873 109057 933855 632721 259819 784272 398751 935451 393059 788917 560334 786155 54986...

output:


result: