結果

問題 No.824 Many Shifts Hard
ユーザー 👑 kmjpkmjp
提出日時 2019-04-28 00:25:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,369 ms / 2,000 ms
コード長 1,544 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 168,316 KB
実行使用メモリ 6,440 KB
最終ジャッジ日時 2023-08-20 04:44:36
合計ジャッジ時間 13,507 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,160 KB
testcase_01 AC 5 ms
6,156 KB
testcase_02 AC 54 ms
6,268 KB
testcase_03 AC 320 ms
6,156 KB
testcase_04 AC 275 ms
6,160 KB
testcase_05 AC 954 ms
6,180 KB
testcase_06 AC 21 ms
6,176 KB
testcase_07 AC 221 ms
6,224 KB
testcase_08 AC 738 ms
6,176 KB
testcase_09 AC 704 ms
6,256 KB
testcase_10 AC 67 ms
6,252 KB
testcase_11 AC 174 ms
6,208 KB
testcase_12 AC 367 ms
6,440 KB
testcase_13 AC 533 ms
6,164 KB
testcase_14 AC 900 ms
6,188 KB
testcase_15 AC 789 ms
6,180 KB
testcase_16 AC 64 ms
6,176 KB
testcase_17 AC 890 ms
6,276 KB
testcase_18 AC 5 ms
6,440 KB
testcase_19 AC 898 ms
6,260 KB
testcase_20 AC 1,369 ms
6,192 KB
testcase_21 AC 8 ms
6,192 KB
testcase_22 AC 1,368 ms
6,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll from[302][302][2];
ll to[302][302][2];
ll mo=1000000007;
ll ret;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	
	for(i=1;i<=min(N,K);i++) from[i-1][i][0]++;
	from[K][K+1][1]=1;
	FOR(i,K) {
		ZERO(to);
		for(x=0;x<=K;x++) for(y=x+1;y<=K+1;y++) FOR(j,2) {
			if(x==0) {
				// take y
				if(y-1>x) (to[x][y-1][j]+=from[x][y][j])%=mo;
				// other
				(to[x][y][j]+=from[x][y][j]*(N-1))%=mo;
			}
			else {
				// take x;
				(to[x-1][y][j]+=from[x][y][j])%=mo;
				// take y
				if(y-1>x) (to[x][y-1][j]+=from[x][y][j])%=mo;
				// other
				(to[x][y][j]+=from[x][y][j]*(N-2))%=mo;
			}
		}
		
		swap(from,to);
	}
	
	for(x=0;x<=K;x++) for(y=x+1;y<=K;y++) (ret+=y*from[x][y][0])%=mo;
	for(y=1;y<=K+1;y++) {
		ll pat=0;
		for(x=0;x<y;x++) pat+=from[x][y][1];
		pat%=mo;
		for(i=K+1;i<=N;i++) (ret+=pat*(i-(K+1-y)))%=mo;
	}
	cout<<ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0