This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int main() { | |
| #ifdef wxh010910 | |
| freopen("input.txt", "r", stdin); | |
| #endif | |
| ios::sync_with_stdio(false); | |
| cin.tie(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MCMF { | |
| struct arc { | |
| const int to, next, cost; | |
| mutable int cap; | |
| }; | |
| const int n_node; | |
| vi head; | |
| vector<arc> e; | |
| mutable vi d; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod = 1e9+7; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| //#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename T> | |
| T inverse(T a, T m) { | |
| T u = 0, v = 1; | |
| while (a != 0) { | |
| T t = m / a; | |
| m -= t * a; swap(a, m); | |
| u -= t * v; swap(u, v); | |
| } | |
| assert(m == 1); | |
| return u; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod = 1e9+7; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| //#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod = 1e9+7; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| //#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int mod = 998244353; | |
| #ifdef LOCAL | |
| //#define _GLIBCXX_DEBUG | |
| // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 | |
| #endif | |
| //#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| // Andrew He's modular-arithmetic class | |
| template <int MOD_> struct modnum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* a tutorial on Gauss-Jordan elimination: https://cp-algorithms.com/linear_algebra/linear-system-gauss.html | |
| From the article: | |
| Strictly speaking, the method described below should be called "Gauss-Jordan", or Gauss-Jordan elimination, | |
| because it is a variation of the Gauss method, described by Jordan in 1887. | |
| */ | |
| using num = modnum<1000003>; | |
| using mat = vv<num>; | |
| using vec = vector<num>; | |
| // precondition: 系数矩阵不含0,否则需要选主元。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // source: https://codeforces.com/contest/1151/submission/52969000 | |
| #ifndef ___CLASS_MODINT | |
| #define ___CLASS_MODINT | |
| #include <cstdint> | |
| template<std::uint32_t mod> | |
| class modint { | |
| private: | |
| std::uint32_t n; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // source: https://codeforces.com/contest/1151/submission/52973403 | |
| template <int MOD_> struct modnum { | |
| static constexpr int MOD = MOD_; | |
| static_assert(MOD_ > 0, "MOD must be positive"); | |
| private: | |
| using ll = long long; | |
| int v; |