Submission #744971

# Submission time Handle Problem Language Result Execution time Memory
744971 2023-05-19T09:15:05 Z sword060 Magneti (COCI21_magneti) C++17
10 / 110
1000 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
const int N=10005,M=1e9+7;
int x,k,dp[N][1<<10][11],dp2[N][51],a[N];
int rec(int i,int msk,int lst){
  if(i>k)return 0;
  if((msk^(1<<lst))==0)return k-i+1;
  if(~dp[i][msk][lst])return dp[i][msk][lst];
  int ret=rec(i+1,msk,lst);
  if(ret>=M)ret-=M;
  for(int nxt=0;nxt<x;nxt++)
    if(msk&(1<<nxt)){
      ret+=rec(i+max(a[lst+1],a[nxt+1]),msk^(1<<lst),nxt);
      if(ret>=M)ret-=M;
    }
  return dp[i][msk][lst]=ret;
}
int rec2(int i,int j){
  if(i>k)return 0;
  if(j==1)return k-i+1;
  if(~dp2[i][j])return dp2[i][j];
  long long ret=(((rec2(i+a[1],j-1)*1LL*j)%M)+(rec2(i+1,j)%M))%M;
  return dp2[i][j]=ret;
}
int main(){
  ios::sync_with_stdio(0);cin.tie(0);
  cin>>x>>k;
  bool f=1;
  for(int i=1;i<=x;i++)cin>>a[i],f&=(a[i]==a[1]);
  if(!f){
    memset(dp,-1,sizeof(dp));
    long long sum=0;
    for(int i=0;i<x;i++)sum=(sum+rec(1,(1<<x)-1,i))%M;
    cout<<sum;
  }else{
    memset(dp2,-1,sizeof(dp2));
    cout<<rec2(1,x);
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2900 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 3 ms 2388 KB Output is correct
6 Correct 8 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 2 ms 2516 KB Output is correct
10 Correct 1 ms 2244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 442216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 602 ms 524288 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2900 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 3 ms 2388 KB Output is correct
6 Correct 8 ms 2772 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 2 ms 2516 KB Output is correct
10 Correct 1 ms 2244 KB Output is correct
11 Execution timed out 1095 ms 442216 KB Time limit exceeded
12 Halted 0 ms 0 KB -