QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#400224 | #7012. Rikka with An Unnamed Temple | hos_lyric | AC ✓ | 9922ms | 365680kb | C++14 | 7.7kb | 2024-04-27 05:40:07 | 2024-04-27 05:40:07 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 1000000007;
using Mint = ModInt<MO>;
constexpr Int INF = 1001001001001001001LL;
using Pair = pair<Int, Mint>;
constexpr Pair ZERO(-INF, 0);
Pair update(Pair &t, const Pair &f, Int c) {
const Int score = f.first + c;
if (t.first < score) {
t.first = score;
t.second = f.second;
} else if (t.first == score) {
t.second += f.second;
}
return t;
}
Pair update(Pair &t, const Pair &f, const Pair &g) {
const Int score = f.first + g.first;
if (t.first < score) {
t.first = score;
t.second = f.second * g.second;
} else if (t.first == score) {
t.second += f.second * g.second;
}
return t;
}
int N, M;
vector<int> W;
vector<Int> C;
vector<int> A, B;
int K, T;
vector<vector<int>> graph, hparg;
vector<int> vis;
vector<int> us;
void dfs(int u) {
if (vis[u]++) return;
for (const int v : hparg[u]) dfs(v);
us.push_back(u);
}
void trans(Pair *t, const Pair *f, int w, Int c) {
for (int k = 0, kk = w; k < K; ++k, ++kk) {
if (kk == K) kk = 0;
update(t[kk], f[k], c);
}
}
void check(Pair &t, const Pair *f, const Pair *g) {
for (int k = 0, kk = T; k < K; ++k, --kk) {
update(t, f[k], g[kk]);
if (kk == 0) kk = K;
}
}
vector<Pair> ans;
// f[u]: [src, u]-path, g[u]: [u, snk]-path
Pair f[100'010][110], g[100'010][110];
Pair save[100'010][110];
/*
f[src, l) OK
g[r, snk] OK
p: considered all ways to skip us[l, r)
*/
void rec(int l, int r, Pair p) {
// cerr<<"[rec] "<<l<<" "<<r<<" "<<p<<endl;
if (l + 1 == r) {
ans[us[l]] = p;
} else {
const int mid = (l + r) / 2;
{
Pair pp = p;
for (int x = r; --x >= mid; ) {
for (const int y : hparg[x]) if (y < l) check(pp, f[y], g[x]);
}
rec(l, mid, pp);
}
{
Pair pp = p;
for (int x = l; x < mid; ++x) {
for (const int y : graph[x]) if (r <= y) check(pp, f[x], g[y]);
}
rec(mid, r, pp);
}
}
}
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d%d", &N, &M);
W.resize(N);
C.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d%lld", &W[u], &C[u]);
}
A.resize(M);
B.resize(M);
for (int i = 0; i < M; ++i) {
scanf("%d%d", &A[i], &B[i]);
--A[i];
--B[i];
}
scanf("%d%d", &K, &T);
for (int u = 0; u < N; ++u) {
W[u] %= K;
}
T %= K;
graph.assign(N, {});
hparg.assign(N, {});
for (int i = 0; i < M; ++i) {
graph[A[i]].push_back(B[i]);
hparg[B[i]].push_back(A[i]);
}
vis.assign(N, 0);
us.clear();
dfs(N - 1);
// cerr<<"us = "<<us<<endl;
// reindex
const int usLen = us.size();
vector<int> ids(N, -1);
for (int x = 0; x < usLen; ++x) ids[us[x]] = x;
graph.assign(usLen, {});
hparg.assign(usLen, {});
for (int i = 0; i < M; ++i) {
const int x = ids[A[i]];
const int y = ids[B[i]];
if (~x && ~y) {
graph[x].push_back(y);
hparg[y].push_back(x);
}
}
const int src = ids[0], snk = ids[N - 1];
assert(~src && ~snk);
for (int x = 0; x < usLen; ++x) {
fill(f[x], f[x] + K, ZERO);
fill(g[x], g[x] + K, ZERO);
}
f[src][W[us[src]]] = Pair(C[us[src]], 1);
for (int x = src; x <= snk; ++x) {
for (const int y : hparg[x]) trans(f[x], f[y], W[us[x]], C[us[x]]);
}
g[snk][W[us[snk]]] = Pair(C[us[snk]], 1);
for (int x = snk; x >= src; --x) {
for (const int y : graph[x]) trans(g[x], g[y], W[us[x]], C[us[x]]);
}
// cerr<<"f[snk] = ";pv(f[snk],f[snk]+K);
// cerr<<"g[src] = ";pv(g[src],g[src]+K);
ans.assign(N, f[snk][T]);
rec(src, snk + 1, ZERO);
for (int u = 0; u < N; ++u) {
if (ans[u].first >= 0) {
printf("%lld %u\n", ans[u].first, ans[u].second.x);
} else {
puts("-1");
}
}
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4120kb
input:
1 4 5 1 2 2 3 3 4 4 2 1 2 1 3 2 4 3 4 1 4 5 3
output:
-1 8 1 -1 -1
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 1086ms
memory: 4880kb
input:
840 300 2000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
-1 26 4598303 26 5863883 26 5015595 26 5885768 26 5825352 26 5282239 26 5677503 26 5663242 26 5549866 26 5865190 26 5748616 26 5885768 26 5833529 26 5635401 26 5885768 26 4779744 26 2604267 26 5001275 26 5885768 26 5820512 26 4314551 26 5885768 26 4334970 26 5885768 26 5712718 26 3266408 26 5807851 ...
result:
ok 252000 lines
Test #3:
score: 0
Accepted
time: 5651ms
memory: 354220kb
input:
10 100000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
-1 92971 21 93151 80261 92971 66888304 93061 1636195 92971 1273 92971 4510 93151 287907743 92881 77902034 92881 77902034 93061 152329005 92791 11621 93061 1149299 92881 77902034 93061 1375637 92881 3146874 93241 331637001 92521 2323746 92971 74019096 93241 1634966 92971 49606952 93061 67095587 93241...
result:
ok 1000000 lines
Test #4:
score: 0
Accepted
time: 9922ms
memory: 364400kb
input:
10 100000 199996 209716784 457585002 684116471 390878750 684117472 390878750 684116198 390878750 684120293 390878750 684118746 390878750 684123023 390878750 684115288 390878750 684119383 390878750 684119747 390878750 684123387 390878750 684119201 390878750 684118200 390878750 684122841 390878750 684...
output:
-1 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 1749122861 99997 17491228...
result:
ok 1000000 lines
Test #5:
score: 0
Accepted
time: 1997ms
memory: 365680kb
input:
10 97843 190591 491838654 66190718 63066994 1 888868658 1 199879445 1 999668194 1 494916788 1 599562190 1 667839593 1 312621436 1 313720346 1 118498972 1 365124510 1 555323904 1 363282628 1 958103770 1 987214655 1 250893535 1 38283294 1 453193983 1 77880110 1 703150923 1 818318041 1 999001283 1 7817...
output:
-1 648319345 887614448 648319598 695396893 648319566 645311746 648319343 887614448 648319448 695396893 648319283 645311746 648319557 852744899 648319501 938666705 648319548 917998978 648319165 852744899 648319315 938666705 648319502 731232806 648319405 731232806 648319594 852743836 648319602 9386656...
result:
ok 941270 lines