AtCoder Grand Contest 013

Submission #1358877

Source codeソースコード

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=1000;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int mod=1e9+7;
struct M{ int a[3][3]; };
inline M operator + (const M &a,const M &b) {
	M ans={};
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			ans.a[i][j]=(a.a[i][j]+b.a[i][j])%mod;
	return ans;
}
inline M operator * (const M &a,const int &b) {
	M ans;
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			ans.a[i][j]=1LL*a.a[i][j]*b%mod;
	return ans;
}
inline M operator * (const M &a,const M &b) {
	M ans={};
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			for (int k=0;k<3;k++)
				ans.a[i][j]=(ans.a[i][j]+1LL*a.a[i][k]*b.a[k][j])%mod;
	return ans;
}
const M zero=(M){{{0,1,3},{0,0,0},{0,0,0}}};
const M base=(M){{{4,1,0},{mod-2,0,1},{1,0,0}}};//f(n)=4f(n-1)-2f(n-2)+f(n-3)
inline M qpow(int y) {
	M ans={},x=base;
	ans.a[0][0]=ans.a[1][1]=ans.a[2][2]=1;
	while (y) {
		if (y&1) ans=ans*x;
		x=x*x;y>>=1;
	}
	return ans;
}
int x[N];
int main()
{
	int n=gi(),m=gi(),i,ans,x,last=0,t;M sum={};
	ans=(zero*qpow(n)).a[0][0];
	for (i=1;i<=m;i++,last=x) {
		x=gi();
		sum=sum*qpow(x-last);
		t=(zero*qpow(x)).a[0][0];
		t=(t-sum.a[0][0]+mod)%mod;
		ans=(ans-1LL*t*(zero*qpow(n-x)).a[0][0]%mod+mod)%mod;
		sum=sum+zero*t;
	}
	printf("%d\n",ans);
	return 0;
}

Submission

Task問題 E - Placing Squares
User nameユーザ名 laofu
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1600
Source lengthソースコード長 1664 Byte
File nameファイル名
Exec time実行時間 811 ms
Memory usageメモリ使用量 384 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt
All 1600 / 1600 sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt,subtask_1_19.txt,subtask_1_20.txt,subtask_1_21.txt,subtask_1_22.txt,subtask_1_23.txt,subtask_1_24.txt,subtask_1_25.txt,subtask_1_26.txt,subtask_1_27.txt,subtask_1_28.txt,subtask_1_29.txt,subtask_1_30.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sample_04.txt AC 1 ms 256 KB
subtask_1_01.txt AC 254 ms 256 KB
subtask_1_02.txt AC 55 ms 256 KB
subtask_1_03.txt AC 145 ms 256 KB
subtask_1_04.txt AC 391 ms 256 KB
subtask_1_05.txt AC 808 ms 256 KB
subtask_1_06.txt AC 811 ms 256 KB
subtask_1_07.txt AC 676 ms 384 KB
subtask_1_08.txt AC 683 ms 256 KB
subtask_1_09.txt AC 8 ms 256 KB
subtask_1_10.txt AC 6 ms 256 KB
subtask_1_11.txt AC 7 ms 256 KB
subtask_1_12.txt AC 3 ms 256 KB
subtask_1_13.txt AC 3 ms 256 KB
subtask_1_14.txt AC 5 ms 256 KB
subtask_1_15.txt AC 2 ms 256 KB
subtask_1_16.txt AC 5 ms 256 KB
subtask_1_17.txt AC 125 ms 256 KB
subtask_1_18.txt AC 313 ms 256 KB
subtask_1_19.txt AC 1 ms 256 KB
subtask_1_20.txt AC 389 ms 256 KB
subtask_1_21.txt AC 1 ms 256 KB
subtask_1_22.txt AC 1 ms 256 KB
subtask_1_23.txt AC 1 ms 256 KB
subtask_1_24.txt AC 1 ms 256 KB
subtask_1_25.txt AC 1 ms 256 KB
subtask_1_26.txt AC 1 ms 256 KB
subtask_1_27.txt AC 1 ms 256 KB
subtask_1_28.txt AC 1 ms 256 KB
subtask_1_29.txt AC 1 ms 256 KB
subtask_1_30.txt AC 1 ms 256 KB