QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#597704 | #9347. Competition in Swiss-system | kjhhjki | ML | 0ms | 0kb | C++20 | 3.3kb | 2024-09-28 18:30:09 | 2024-09-28 18:30:11 |
answer
#include <bits//stdc++.h>
using i64 = long long;
using i128 = __int128;
std::ostream& operator<<(std::ostream &os, i128 x)
{
std::string s;
do {
s.push_back(x % 10 + '0');
x /= 10;
}while(x);
std::ranges::reverse(s);
os << s;
return os;
}
i128 gcd(i128 a, i128 b)
{
if(b == 0) {
return a;
}
return gcd(b, a % b);
}
struct fact
{
i128 p, q;
auto operator<=>(const fact &o) const { return p * o.q <=> q * o.p; }
fact(i128 p = 0, i128 q = 1): p(p), q(q)
{
update();
if(*this < fact(1, 3)) *this = fact(1, 3);
}
void update()
{
i128 g = gcd(p, q);
p /= g; q /= g;
}
constexpr fact operator+(const fact &o) const { return fact(p * o.q + q * o.p, q * o.q); }
constexpr fact operator-(const fact &o) const { return fact(p * o.q - q * o.p, q * o.q); }
constexpr fact operator*(const fact &o) const { return fact(p * o.p, q * o.q); }
constexpr fact operator/(const fact &o) const { return fact(p * o.q, q * o.p); }
constexpr fact& operator+=(const fact &o) { return *this = *this + o; }
constexpr fact& operator-=(const fact &o) { return *this = *this - o; }
constexpr fact& operator*=(const fact &o) { return *this = *this * o; }
constexpr fact& operator/=(const fact &o) { return *this = *this / o; }
friend std::ostream& operator<<(std::ostream &os, const fact &o)
{
return os << o.p << '/' << o.q;
}
};
void solve()
{
int n, m;
std::cin >> n >> m;
std::vector<int> a(m + 1);
for(int i = 1; i <= m; ++i) {
std::cin >> a[i];
}
std::vector<std::vector<int>> oppo(n + 1);
std::vector<int> mp(n + 1), gp(n + 1), cnt(n + 1);
std::vector<fact> omw(n + 1), gw = omw, ogw = gw;
for(int i = 1; i <= m; ++i) {
std::vector<bool> vis(n + 1);
for(int j = 0; j < a[i]; ++j) {
int p1, p2, w1, w2, d;
std::cin >> p1 >> p2 >> w1 >> w2 >> d;
vis[p1] = vis[p2] = true;
gp[p1] += 3 * w1 + d;
gp[p2] += 3 * w2 + d;
if(w1 > w2) {
mp[p1] += 3;
} else if(w1 < w2) {
mp[p2] += 3;
} else {
mp[p1] += 1;
mp[p2] += 1;
}
oppo[p1].push_back(p2);
oppo[p2].push_back(p1);
cnt[p1] += 3 * (w1 + w2 + d);
cnt[p2] += 3 * (w1 + w2 + d);
}
for(int i = 1; i <= n; ++i) {
if(!vis[i]) {
mp[i] += 3;
gp[i] += 6;
cnt[i] += 6;
}
}
std::cout << "Round " << i << '\n';
for(int j = 1; j <= n; ++j) {
omw[j] = ogw[j] = 0;
for(auto x: oppo[j]) {
omw[j] += fact(mp[x], 3 * i);
ogw[j] += fact(gp[x], cnt[x]);
}
if(oppo[j].size()) omw[j] /= oppo[j].size(), ogw[j] /= oppo[j].size();
std::cout << mp[j] << ' ' << omw[j] << ' ' << fact(gp[j], cnt[j]) << ' ' << ogw[j] << '\n';
}
}
}
int main()
{
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int T = 1;
std::cin >> T;
while(T --) solve();
return 0;
}
详细
Test #1:
score: 0
Memory Limit Exceeded
input:
2 2 3 0 1 1 1 2 2 0 1 1 2 1 1 1 3 2 1 1 1 2 0 2 0 2 3 2 0 0