結果
| 問題 |
No.1336 Union on Blackboard
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 22:10:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,899 bytes |
| コンパイル時間 | 1,848 ms |
| コンパイル使用メモリ | 194,944 KB |
| 最終ジャッジ日時 | 2025-01-17 19:32:35 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
/**
* author: shu8Cream
* created: 15.01.2021 21:11:10
**/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint{
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n; cin >> n;
vector<mint> a(n);
rep(i,n) cin >> a[i];
mint last=0;
rep(i,n-1){
int len = a.size();
last=a[len-1]+a[len-2] + a[len-1]*a[len-2];
a.pop_back();
a.pop_back();
a.push_back(last);
}
cout << last << endl;
}
}