版本比较
题解:P3543 [POI 2012] WYR-Leveling Ground
正文
增加 5 行删除 5 行
98 行未改动991001011021031031041051061071081091101111121121131141151161171181191191201211221238 行未改动13213313413513613613713813914023 行未改动1641651661671681681691701711725 行未改动98 行未改动```cppconst int N = 1e5 + 5;
int n, a, b, g, h[N], d[N];void exgcd(int128 a, int128 b, int128& x, int128& y) void exgcd(int128 a, int128 b, int128& x, int128& y){b ? (exgcd(b, a % b, y, x), y -= a / b * x) : (x = 1, y = 0);}tuple<int128, int128, int128> info[N];int128 _abs(int128 x) {return x >= 0 ? x : -x;} // 不手写你会失心疯的
void _main() { cin >> n >> a >> b, g = gcd(a, b); for (int i = 1; i <= n; i++) { cin >> h[i]; if (h[i] % g) return cout << -1, void(); if (h[i] % g) return cout << -1, void(); h[i] /= g; } for (int i = 1; i <= n + 1; i++) d[i] = h[i] - h[i - 1]; n++, a /= g, b /= g; if (a < b) swap(a, b); int128 x0, y0; exgcd(a, b, x0, y0);
int128 cost = 0, cur = 0; auto work1 = [&]() -> void { for (int i = 1; i <= n; i++) { // x * a + y * b = -d[i]8 行未改动 }; work1(); int offset = -(cur / b), dir = offset < 0 ? -1 : 1; if (offset == 0) return cout << static_cast<u64>(cost / 2), void();
vector<pair<int128, int128>> vec; auto work2 = [&]() -> void { for (int i = 1; i <= n; i++) { auto [x, y, p] = info[i];23 行未改动 } } }; work2();
sort(vec.begin(), vec.end()); int128 res = cost, need = _abs(offset); for (auto [val, cnt] : vec) { int128 w = min(cnt, need);5 行未改动