結果
| 問題 |
No.797 Noelちゃんとピラミッド
|
| コンテスト | |
| ユーザー |
tRue_math
|
| 提出日時 | 2019-03-16 16:20:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,787 bytes |
| コンパイル時間 | 716 ms |
| コンパイル使用メモリ | 76,280 KB |
| 実行使用メモリ | 10,908 KB |
| 最終ジャッジ日時 | 2024-07-01 22:32:51 |
| 合計ジャッジ時間 | 4,611 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 59 |
ソースコード
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
class UnionFind {
public:
//親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> Parent;
//作るときはParentの値を全て-1にする
//こうすると全てバラバラになる
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)];//親をとってきたい
}
//AとBをくっ付ける
bool connect(int A, int B) {
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらひっくり返しちゃう。
if (size(A) < size(B)) swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
};
//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long d = extGCD(b, a%b, y, x);
y -= a / b * x;
return d;
}
bool check(int a, int b) {
return a > b;
}
int main() {
llint n;
cin >> n;
vllint a(n);
rep(i, n) {
cin >> a[i];
}
llint cnt;
llint tmp;
llint y;
llint ans = 0;
rep(i, n) {
cnt = 1;
rep(j, i) {
cnt *= (n - j - 1);
cnt %= 1000000007;
}
rep(j, i) {
//cnt/=j+1をしたい
//逆元をtmpに入れる
extGCD(j + 1, 1000000007, tmp, y);
cnt *= tmp;
cnt %= 1000000007;
if (cnt < 0) {
cnt += 1000000007;
}
cnt %= 1000000007;
}
cnt *= a[i];
cnt %= 1000000007;
ans += cnt;
}
cout << ans << endl;
return 0;
}
tRue_math