結果
| 問題 | No.3527 Minimum Abs Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-04 03:23:17 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,621 bytes |
| 記録 | |
| コンパイル時間 | 3,366 ms |
| コンパイル使用メモリ | 192,524 KB |
| 実行使用メモリ | 11,860 KB |
| 最終ジャッジ日時 | 2026-11-04 03:23:35 |
| 合計ジャッジ時間 | 8,674 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 21 |
ソースコード
#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 modpow(ll a, ll b, ll p){
a%=p;
ll ans=1;
while(b>0){
if(b%2==1) ans=(ans*a)%p;
b/=2;
a=(a*a)%p;
}
return ans;
}
int main(void){
int n; cin >> n;
vector<frac> p;
vector<ll> a(n), b(n);
for(auto&x:a) cin >> x;
for(auto&x:b) cin >> x;
for(int i=0; i<n; i++){
if(a[i]!=0) p.emplace_back(b[i], a[i]);
}
sort(begin(p), end(p));
int m=p.size(), mid=m/2;
if(m%2==0) mid--;
ll mod=1e9+7, ans=p[mid].bunsi*modpow(p[mid].bumbo, mod-2, mod)%mod;
cout << (ans+mod)%mod << endl;
return 0;
}