結果
| 問題 | No.3362 積分!!! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-16 15:36:49 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,541 bytes |
| 記録 | |
| コンパイル時間 | 1,193 ms |
| コンパイル使用メモリ | 180,312 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-10-21 16:26:18 |
| 合計ジャッジ時間 | 2,996 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 14 WA * 1 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
struct frac{
ll bunsi, bumbo;
frac(ll a, ll b=1):bunsi(a), bumbo(b){
normalize();
}
ll gcd(ll a, ll b){
if(b==0) return a;
else return gcd(b, a%b);
}
void normalize(){
if(bumbo<0) bunsi*=-1, bumbo*=-1;
ll g=gcd(abs(bunsi), abs(bumbo));
bunsi/=g, bumbo/=g;
}
frac& operator+=(const frac& other){
bunsi=bunsi*other.bumbo+other.bunsi*bumbo;
bumbo*=other.bumbo;
normalize();
return *this;
}
frac& operator-=(const frac& other){
bunsi=bunsi*other.bumbo-other.bunsi*bumbo;
bumbo*=other.bumbo;
normalize();
return *this;
}
frac& operator*=(const frac& other){
bunsi*=other.bunsi;
bumbo*=other.bumbo;
normalize();
return *this;
}
frac& operator/=(const frac& other){
bunsi*=other.bumbo;
bumbo*=other.bunsi;
normalize();
return *this;
}
frac operator+()const{
return *this;
}
frac operator-()const{
return frac(-bunsi, bumbo);
}
frac operator+(const frac& other)const{
frac ans=*this;
return ans+=other;
}
frac operator-(const frac& other)const{
frac ans=*this;
return ans-=other;
}
frac operator*(const frac& other)const{
frac ans=*this;
return ans*=other;
}
frac operator/(const frac& other)const{
frac ans=*this;
return ans/=other;
}
bool operator==(const frac& other)const{
return bunsi==other.bunsi&&bumbo==other.bumbo;
}
bool operator!=(const frac& other)const{
return !(*this==other);
}
bool operator<(const frac& other)const{
return (__int128)bunsi*other.bumbo<(__int128)other.bunsi*bumbo;
}
bool operator>(const frac& other) const {
return other<*this;
}
bool operator<=(const frac& other)const{
return !(*this>other);
}
bool operator>=(const frac& other)const{
return !(*this<other);
}
friend ostream& operator<<(ostream& os, const frac& f){
if (f.bumbo == 1) os << f.bunsi;
else os << f.bunsi << "/" << f.bumbo;
return os;
}
};
ll f(ll p, ll q){
if(p>=0) return p/q;
else{
ll pp=-p;
return -(pp+q-1)/q;
}
}
int main(void){
int n, a, b; cin >> n >> a >> b;
vector<ll> k(n+1), pa(n+2, 1), pb(n+2, 1);
for(auto&x:k) cin >> x;
for(int i=1; i<n+2; i++) pa[i]=pa[i-1]*a, pb[i]=pb[i-1]*b;
frac ans(0, 1);
for(int i=0; i<=n; i++){
frac now(k[i]*(pb[i+1]-pa[i+1]), i+1);
ans+=now;
}
ll p=ans.bunsi, q=ans.bumbo;
cout << f(p, q) << endl;
return 0;
}