QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#473112 | #4741. Powódź | Starrykiller | 0 | 12ms | 11444kb | C++23 | 4.1kb | 2024-07-11 21:54:28 | 2024-07-11 21:54:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
namespace sk {
// modint: https://www.cnblogs.com/hzy1/p/16344746.html
// Edited by Starrykiller.
using i64=int64_t;
using u64=unsigned i64;
using i32=int32_t;
i32 inverse(i32 a, i32 m) { i32 r=1;
while (a>1) { i32 t=m/a; r=i64(r)*(m-t)%m; a=m-t*a; }
return r;
}
template<i32 mod>
struct static_modint {
i32 x;
static_modint(i64 x) : x(normal(x%mod)) {}
static_modint(i32 x, nullptr_t) : x(x) {}
static_modint(): x(0) {}
inline constexpr i32 normal(i32 x) {
if (x>=mod) x-=mod;
return x+((x>>31)&mod);
}
inline constexpr i32 val() const { return x; }
inline constexpr explicit operator bool() const { return x; }
inline constexpr static_modint inv() const { assert(x!=0); return static_modint(inverse(x,mod),nullptr); }
inline constexpr static_modint pow(i64 x) const { assert(x>=0); static_modint a=*this, res=1;
while (x) { if (x&1) res*=a; a*=a; x>>=1; } return res; }
inline constexpr static_modint operator-() const { return static_modint(mod-x); }
inline constexpr static_modint& operator+=(const static_modint &rhs) { x=normal(x+rhs.x); return *this; }
inline constexpr static_modint& operator-=(const static_modint &rhs) { x=normal(x-rhs.x); return *this; }
inline constexpr static_modint& operator++() { return (*this)+=1; }
inline constexpr static_modint& operator--() { return (*this)-=1; }
inline constexpr static_modint& operator*=(const static_modint &rhs) { x=i64(x)*rhs.x%mod; return *this; }
inline constexpr static_modint& operator/=(const static_modint &rhs) { return *this *= rhs.inv(); }
friend static_modint operator+(const static_modint &lhs, const static_modint &rhs) { auto res=lhs; res+=rhs; return res; }
friend static_modint operator-(const static_modint &lhs, const static_modint &rhs) { auto res=lhs; res-=rhs; return res; }
friend static_modint operator*(const static_modint &lhs, const static_modint &rhs) { auto res=lhs; res*=rhs; return res; }
friend static_modint operator/(const static_modint &lhs, const static_modint &rhs) { auto res=lhs; res/=rhs; return res; }
friend static_modint operator++(static_modint &x, int) { auto tmp=x; x+=1; return tmp; }
friend static_modint operator--(static_modint &x, int) { auto tmp=x; x-=1; return tmp; }
friend std::istream& operator>>(std::istream &is, static_modint &a) { i64 v; is >> v; a=static_modint(v%mod); return is; }
friend std::ostream& operator<<(std::ostream &os, const static_modint &a) { os << a.val(); return os; }
bool operator==(const static_modint& rhs) const { return x==rhs.x; }
bool operator!=(const static_modint& rhs) const { return x!=rhs.x; }
};
using modint998244353=static_modint<998244353>;
using modint1000000007=static_modint<1000000007>;
};
constexpr int MAXN=5e5+10; using ll=sk::modint1000000007;
int n, m, h;
int id(int x, int y) { return (x-1)*m+y; }
struct E { int u, v, w; }; vector<E> e;
int fa[MAXN], siz[MAXN], val[MAXN]; ll f[MAXN];
int get(int x) { return fa[x]==x?x:fa[x]=get(fa[x]); }
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n>>m>>h;
for (int i=1; i<=n; ++i) for (int j=1,w; j<m; ++j)
cin>>w, e.push_back({id(i,j),id(i,j+1),w});
for (int i=1; i<n; ++i) for (int j=1,w; j<=m; ++j)
cin>>w, e.push_back({id(i,j),id(i+1,j),w});
sort(e.begin(),e.end(),[](const E& a, const E& b) { return a.w<b.w; });
for (int i=1; i<=n*m; ++i) siz[fa[i]=i]=1, val[i]=-1; int cur=0;
for (auto [u,v,w]: e) {
u=get(u), v=get(v);
if (u==v) continue;
// cerr<<siz[u]<<' '<<siz[v]<<' '<<w-val[u]<<' '<<w-val[v]<<'\n';
// ans+=ll(siz[u]+siz[v]).pow(1ll*(w-val[u]+1)*(w-val[v]+1));
f[v]=(f[u]+val[u]-w)*(f[v]+val[v]-w);
fa[u]=v; siz[v]+=siz[u]; val[v]=w;
cur=w;
}
ll ans=f[get(1)];
ans+=h-cur;
cout<<ans<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 0ms
memory: 11356kb
input:
3 2 2 1 1 1 1 2 1 1
output:
65
result:
ok 1 number(s): "65"
Test #2:
score: -10
Wrong Answer
time: 0ms
memory: 11444kb
input:
1 10 4 1 2 1 4 1 4 1 2 2
output:
175
result:
wrong answer 1st numbers differ - expected: '8883', found: '175'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 12ms
memory: 10812kb
input:
1 100000 1000 166 614 949 2 12 578 299 170 238 139 139 372 799 9 51 816 997 859 97 850 583 664 233 849 49 679 706 801 937 65 81 858 853 83 56 882 459 392 897 844 734 141 676 75 570 636 673 415 442 243 887 397 904 174 40 523 178 937 206 82 515 500 558 79 595 175 416 634 343 194 307 205 821 743 720 45...
output:
797052078
result:
wrong answer 1st numbers differ - expected: '146179207', found: '797052078'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%