結果

問題 No.2017 Mod7 Parade
ユーザー souta-1326souta-1326
提出日時 2021-07-10 15:51:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 7,847 bytes
コンパイル時間 4,247 ms
コンパイル使用メモリ 241,696 KB
実行使用メモリ 4,804 KB
最終ジャッジ日時 2023-09-17 07:55:00
合計ジャッジ時間 6,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 34 ms
4,496 KB
testcase_04 AC 23 ms
4,376 KB
testcase_05 AC 18 ms
4,376 KB
testcase_06 AC 37 ms
4,468 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 22 ms
4,376 KB
testcase_11 AC 30 ms
4,380 KB
testcase_12 AC 27 ms
4,380 KB
testcase_13 AC 43 ms
4,668 KB
testcase_14 AC 43 ms
4,668 KB
testcase_15 AC 42 ms
4,804 KB
testcase_16 AC 43 ms
4,788 KB
testcase_17 AC 43 ms
4,636 KB
testcase_18 AC 46 ms
4,804 KB
testcase_19 AC 32 ms
4,804 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define PI acos(-1)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define endll "\n"
using namespace std;
using namespace atcoder;
using ll = long long;
template<class T> constexpr inline void input(vector<T> &v){
  for(int i=0;i<v.size();i++) cin >> v[i];
}
template<class T,class S> constexpr inline void input(vector<T> &v,vector<S> &u){
  for(int i=0;i<v.size();i++) cin >> v[i] >> u[i];
}
template<class T,class S,class R> constexpr inline void input(vector<T> &v,vector<S> &u,vector<R> &t){
  for(int i=0;i<v.size();i++) cin >> v[i] >> u[i] >> t[i];
}
template<class T> constexpr inline void input(vector<vector<T>> &v){
  for(int i=0;i<v.size();i++){
    for(int j=0;j<v[i].size();j++) cin >> v[i][j];
  }
}
template<class T> constexpr inline void input_graph(vector<vector<T>> &G,int inputcount,const bool isdirect = false,const bool indexed = 1){
  T a,b;
  for(int i=0;i<inputcount;i++){
    cin >> a >> b;a -= indexed;b -= indexed;
    G[a].emb(b);
    if(!isdirect) G[b].emb(a);
  }
}
template<class T> constexpr inline void output(vector<T> &v,bool space = true){
  if(space){
    for(int i=0;i<v.size()-1;i++) cout << v[i] << " ";
    cout << v.back() << endll;
  }
  else{
    for(int i=0;i<v.size();i++) cout << v[i] << endll;
  }
}
template<class T,class S> constexpr inline void output(vector<T> &v,vector<S> &u){
  for(int i=0;i<v.size();i++) cout << v[i] << " " << u[i] << endll;
}
template<class T,class S,class R> constexpr inline void output(vector<T> &v,vector<S> &u,vector<R> &t){
  for(int i=0;i<v.size();i++) cout << v[i] << " " << u[i] << " " << t[i] << endll;
}
template<class T> constexpr inline void output(vector<vector<T>> &v){
  for(int i=0;i<v.size();i++){
    for(int j=0;j<v[i].size()-1;j++) cout << v[i][j] << " ";
    cout << v[i].back() << endll;
  }
}
template<class T> constexpr inline bool on(T n,T i){
  return n&(1<<i);
}
template<class T,class S> constexpr inline T ceil(T x,S y){
  return (x+y-1)/y;
}
template<class T> constexpr bool isprime(T x){
  for(T i=2;i*i<=x;i++){
    if(x%i == 0) return false; 
  }
  return true;
}
vector<bool> isprime_format(int n){
  vector<bool> P(n+1,1);P[0] = P[1] = 1;
  for(int i=2;i*i<=n;i++){
    if(!P[i]) continue;
    for(int j=i+i;j<=n;j+=i) P[j] = false;
  }
  return P;
}
template<class T> vector<T> dijkstra(T N,vector<T> st,vector<vector<pair<T,T>>> G){
  T fn,fp,i;
  priority_queue<pair<T,T>,vector<pair<T,T>>,greater<>> q;
  vector<T> D(N,-1);
  for(i=0;i<st.size();i++){
    D[st[i]] = 0;
    q.push(mpa(0,st[i]));
  }
  while(!q.empty()){
    fn = q.top().fi;fp = q.top().se;q.pop();
    if(D[fp] < fn) continue;
    for(i=0;i<G[fp].size();i++){
      if(D[G[fp][i].fi] == -1 || D[G[fp][i].fi] > D[fp]+G[fp][i].se){
        D[G[fp][i].fi] = D[fp]+G[fp][i].se;
        q.push(mpa(D[G[fp][i].fi],G[fp][i].fi));
      }
    }
  }
  return D;
}
template<class T> vector<T> dijkstra(T N,T st,vector<vector<pair<T,T>>> G){
  return dijkstra(N,vector<T>({st}),G);
}
template<class T> class WarshallFloyd{
  T N,inf;
  vector<vector<T>> D;
  vector<vector<T>> prev;
  bool isdirect;
  void setting(){
    for(T k=0;k<N;k++){
      for(T i=0;i<N;i++){
        for(T j=0;j<N;j++){
          if(D[i][k] == inf || D[k][j] == inf) continue;
          if(D[i][j] > D[i][k]+D[k][j]){
            D[i][j] > D[i][k]+D[k][j];
            prev[i][j] = prev[k][j];
          } 
        }
      }
    }
  }
public:
  WarshallFloyd(T N,vector<T> &u,vector<T> &v,vector<T> &c,T inf,bool isdirect){
    this->N = N;
    this->inf = inf;
    this->isdirect = isdirect;
    assert(u.size() == v.size());
    vector<vector<T>>(N,vector<T>(N,inf)).swap(D);
    vector<vector<T>>(N,vector<T>(N)).swap(prev);
    for(T i=0;i<N;i++){
      for(T j=0;j<N;j++) prev[i][j] = i;
    }
    for(T i=0;i<N;i++) D[i][i] = 0;
    for(T i=0;i<u.size();i++){
      D[u[i]][v[i]] = min(D[u[i]][v[i]],c[i]);
      if(!isdirect) D[v[i]][u[i]] = min(D[v[i]][u[i]],c[i]);
    }
    setting();
  }
  WarshallFloyd(vector<vector<T>> D,T inf,bool isdirect){
    this->N = D.size();
    this->inf = inf;
    this->D = D;
    this->isdirect = isdirect;
    vector<vector<T>>(N,vector<T>(N)).swap(prev);
    for(T i=0;i<N;i++){
      for(T j=0;j<N;j++) prev[i][j] = i;
    }
    setting();
  }
  void append(T s,T t,T c){
    for(T i=0;i<N;i++){
      for(T j=0;j<N;j++){
        if(D[i][s] != inf && D[t][c] != inf){
          if(D[i][j] > D[i][s]+c+D[t][j]){
            D[i][j] = D[i][s]+c+D[t][j];
            prev[i][j] = prev[t][j];
          }
        }
        if(!isdirect && D[i][t] != inf && D[s][j] != inf){
          if(D[i][j] > D[i][t]+c+D[s][j]){
            D[i][j] = D[i][t]+c+D[s][j];
            prev[i][j] = prev[s][j];
          }
        }
      }
    }
  }
  T at(T i,T j){
    return D[i][j];
  }
  vector<T> Path(T s,T t){
    vector<T> ret;
    ret.emb(t);
    while(t != s) ret.emb(t=prev[s][t]);
    reverse(all(ret));
    return ret;
  }
  bool negative_cycle(){
    for(T i=0;i<N;i++){
      if(D[i][i] < 0) return true;
    }
    return false;
  }
  vector<vector<T>> Graph(){
    return D;
  }
};
template<class T> class mat{
  vector<vector<T>> V;
public:
  constexpr mat(){}
  constexpr mat(int N,int M){
    vector<vector<T>>(N,vector<T>(M)).swap(this->V);
  }
  constexpr mat(vector<vector<T>> &v){
    this->V = v;
  }
  constexpr int height(){return V.size();}
  constexpr int width(){return V[0].size();}
  constexpr T &val(int a,int b){return V[a][b];}
  constexpr vector<T> &val(int a){return V[a];}
  constexpr vector<vector<T>> &val(){return V;}
  //ret(mat[i][j],elem(a[i][k],b[k][j]))
  constexpr mat calc(mat &b,function<T(T,T)> ret = [](T x,T y){return x+y;},function<T(T,T)> elem = [](T x,T y){return x*y;})const{
    vector<vector<T>> c(V.size(),vector<T>(b.width()));
    for(int i=0;i<V.size();i++){
      for(int k=0;k<b.height();k++){
        for(int j=0;j<b.width();j++) c[i][j] = ret(c[i][j],elem(V[i][k],b.val(k,j)));
      }
    }
    return mat(c);
  }
  constexpr mat pow(ll y,function<T(T,T)> ret = [](T x,T y){return x+y;},function<T(T,T)> elem = [](T x,T y){return x*y;}) const {
    mat x = *this,z;
    while(y){
      if(y&1){
        if(z.height() == 0) z = x;
        else z = z.calc(x,ret,elem);
      }
      x = x.calc(x,ret,elem);
      y >>= 1;
    }
    return z;
  }
};
using mint = modint1000000007;
ll solve_main(ll K,const vector<ll> &D,const vector<ll> &L){
  vector<ll> mod7({1,3,2,6,4,5});
  vector<vector<mint>> dp(6,vector<mint>(7));//dp[j%6][k%7] -> これまでの桁数がj,数がk
  vector<vector<mint>> newdp;
  dp[0][0] = 1;
  //後ろからDP
  for(ll i=K-1;i>=0;i--){
    newdp = dp;
    for(ll j=0;j<6;j++){
      //これまでの桁数%6をjとして、足される数(mod7)を求める -> now
      ll now = 0;
      for(ll k=0;k<L[i]%6;k++) now = (now+mod7[(j+k)%6]*D[i])%7;
      for(ll k=0;k<7;k++) newdp[(j+L[i])%6][(k+now)%7] += dp[j][k];
    }
    swap(dp,newdp);
  }
  mint ans = 0;
  for(ll j=0;j<6;j++){
    for(ll k=0;k<7;k++) ans += dp[j][k]*k;
  }
  return ans.val();
}
ll solve_bitfullsearch(ll K,const vector<ll> &D,const vector<ll> &L){
  mint ans = 0;
  vector<ll> mod7({1,3,2,6,4,5});
  for(ll b=0;b<(1<<K);b++){
    ll now = 0;
    ll cnt = 0;
    for(ll i=K-1;i>=0;i--){
      if(!on(b,i)) continue;
      now = (now+(L[i]/6)*21*D[i])%7;
      for(ll j=0;j<L[i]%6;j++) now = (now+mod7[(j+cnt)%6]*D[i])%7;
      cnt = (cnt+L[i])%6;
    }
    ans += now;
  }
  return ans.val();
}
int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  //-----------------------------------------------
  ll K;cin >> K;
  vector<ll> D(K),L(K);input(D,L);
  //cout << solve_bitfullsearch(K,D,L) << endll;
  cout << solve_main(K,D,L) << endll;
}
0