結果

問題 No.695 square1001 and Permutation 4
ユーザー chocoruskchocorusk
提出日時 2018-12-19 11:32:57
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,592 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 86,544 KB
実行使用メモリ 42,508 KB
最終ジャッジ日時 2023-09-30 01:38:38
合計ジャッジ時間 10,516 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 85 ms
7,424 KB
testcase_02 AC 194 ms
23,932 KB
testcase_03 AC 80 ms
24,004 KB
testcase_04 AC 464 ms
23,896 KB
testcase_05 AC 770 ms
23,788 KB
testcase_06 AC 1,789 ms
42,424 KB
testcase_07 AC 835 ms
42,380 KB
testcase_08 AC 516 ms
42,440 KB
testcase_09 AC 1,268 ms
42,408 KB
testcase_10 AC 360 ms
11,576 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int mid=10000000;
int MOD[3]={17, 9920467, 592951213};
int dp[mid];
vector<int> x1, x2;
int n, m;
ll solve(int mod){
  fill(dp, dp+min(mid, n), 0);
  dp[0]=1;
  for(int i=1; i<min(mid, n); i++){
    for(auto x:x1){
      if(i-x>=0) dp[i]=(dp[i]+dp[i-x])%mod;
    }
  }
  if(n<=mid) return (ll)dp[n-1];
  ll ans=0;
  for(auto x:x2){
    for(int i=0; i<n-x; i++){
      ll c1=dp[i], c2=dp[n-1-i-x];
      ans+=(c1*c2);
      ans%=mod;
    }
  }
  for(int i=0; i<n; i++){
    int c=0;
    for(auto x:x1){
      c+=dp[(i+mid-x)%mid];
      c%=mod;
    }
    dp[i]=c;
  }
  ans+=dp[n-1];
  ans%=mod;
  return ans;
}
ll extgcd(ll a, ll b, ll& x, ll& y){
	ll d=a;
	if(b!=0){
		d=extgcd(b, a%b, y, x);
		y-=(a/b)*x;
	}else{
		x=1, y=0;
	}
	return d;
}
ll inv(ll a, ll p){
	ll x, y;
	extgcd(a, p, x, y);
	if(x<0){
		return p-(-x%p);
	}else{
		return x%p;
	}
}
int main()
{
	cin>>n>>m;
  for(int i=0; i<m; i++){
    int x;cin>>x;
    if(x<mid) x1.push_back(x);
    else x2.push_back(x);
  }
  ll ans[3];
  for(int i=0; i<3; i++) ans[i]=solve(MOD[i]);
  ll a[3]; a[0]=ans[0];
  a[1]=(ans[1]+MOD[1]-a[0])*inv(MOD[0], MOD[1])%MOD[1];
  a[2]=(ans[2]-(a[1]*MOD[0]+a[0])%MOD[2]+MOD[2])*inv(MOD[0]*MOD[1]%MOD[2], MOD[2])%MOD[2];
  cout<<a[0]+a[1]*MOD[0]+a[2]*MOD[0]*MOD[1]<<endl;
	return 0;
}
0