#include <bits/stdc++.h>
const int N = 10000 + 5, M = 1000 + 5, INF = 0xfffffff;
int n, m, k, dp[N][M], ans = INF;
bool pipe_count[N];
struct {
int x, y;
} touch[N];
struct {
int l, h;
} pipe[N];
inline void test_output_dp() {
std::fprintf(stderr, "test output dp:\n");
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
std::fprintf(stderr, "[%d, %d]:%d, ", i, j, dp[i][j]);
}
std::fprintf(stderr, "\n");
}
}
inline void test_output_pipe() {
std::fprintf(stderr, "test output pipe:\n");
for (int i = 0; i <= n; i++) {
std::fprintf(stderr, "[%d]: [%d, %d]\n", i, pipe[i].l, pipe[i].h);
}
}
int main() {
std::cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
std::cin >> touch[i].x >> touch[i].y;
pipe[i].l = 1;
pipe[i].h = m;
}
pipe[n].l = 1;
pipe[n].h = m;
for (int i = 0, p; i < k; i++) {
std::cin >> p;
std::cin >> pipe[p].l >> pipe[p].h;
pipe[p].l++;
pipe[p].h--;
pipe_count[p] = true;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) {
dp[i][j] = INF;
if (j >= pipe[i].l && j <= pipe[i].h) {
if (j + touch[i - 1].y <= pipe[i - 1].h) {
dp[i][j] = dp[i - 1][j + touch[i - 1].y];
}
if (j < m) {
for (int k = 1; j - k * touch[i - 1].x >= pipe[i - 1].l; k++) {
if (j - k * touch[i - 1].x <= pipe[i - 1].h) {
dp[i][j] = std::min(dp[i][j], dp[i - 1][j - k * touch[i - 1].x] + k);
}
}
} else {
dp[i][j] = std::min(dp[i][j], dp[i - 1][j] + 1);
for (int k = pipe[i - 1].l; k <= std::min(pipe[i - 1].h, m - 1); k++) {
dp[i][j] = std::min(dp[i][j], dp[i - 1][k] + (j - k + touch[i - 1].x - 1) / touch[i - 1].x);
}
}
}
}
}
for (int i = 1; i <= m; i++) {
ans = std::min(ans, dp[n][i]);
}
// test_output_dp();
// test_output_pipe();
if (ans < INF) {
std::cout << "1\n" << ans;
} else {
std::cout << "0\n";
for (int i = n; i >= 0; i--) {
for (int j = 0; j <= m; j++) {
if (dp[i][j] < INF) {
ans = 0;
for (int k = 0; k < i; k++) {
ans += pipe_count[k];
}
std::cout << ans;
return 0;
}
}
}
}
}
Windows上编译可以,但是交到洛谷上
/tmp/compiler_zuw_wyh9/src:10:9: 错误:‘<unnamed struct> pipe [10005]’ redeclared as different kind of entity
10 | } pipe[N];
| ^
In file included from /nix/store/79624djlfdc0a6anji2rwqd9p9ycqi8h-glibc-2.34-210-dev/include/bits/sigstksz.h:24,
from /nix/store/79624djlfdc0a6anji2rwqd9p9ycqi8h-glibc-2.34-210-dev/include/signal.h:328,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/csignal:42,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:43,
from /tmp/compiler_zuw_wyh9/src:1:
/nix/store/79624djlfdc0a6anji2rwqd9p9ycqi8h-glibc-2.34-210-dev/include/unistd.h:437:12: 附注:previous declaration ‘int pipe(int*)’
437 | extern int pipe (int __pipedes[2]) __THROW __wur;
| ^~~~
/tmp/compiler_zuw_wyh9/src: 在函数‘void test_output_pipe()’中:
/tmp/compiler_zuw_wyh9/src:23:53: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
23 | std::fprintf(stderr, "[%d]: [%d, %d]\n", i, pipe[i].l, pipe[i].h);
| ^
/tmp/compiler_zuw_wyh9/src:23:55: 错误:对成员‘l’的请求出现在‘*(pipe + ((sizetype)i))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
23 | std::fprintf(stderr, "[%d]: [%d, %d]\n", i, pipe[i].l, pipe[i].h);
| ^
/tmp/compiler_zuw_wyh9/src:23:64: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
23 | std::fprintf(stderr, "[%d]: [%d, %d]\n", i, pipe[i].l, pipe[i].h);
| ^
/tmp/compiler_zuw_wyh9/src:23:66: 错误:对成员‘h’的请求出现在‘*(pipe + ((sizetype)i))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
23 | std::fprintf(stderr, "[%d]: [%d, %d]\n", i, pipe[i].l, pipe[i].h);
| ^
/tmp/compiler_zuw_wyh9/src: 在函数‘int main()’中:
/tmp/compiler_zuw_wyh9/src:30:9: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
30 | pipe[i].l = 1;
| ^
/tmp/compiler_zuw_wyh9/src:30:11: 错误:对成员‘l’的请求出现在‘*(pipe + ((sizetype)i))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
30 | pipe[i].l = 1;
| ^
/tmp/compiler_zuw_wyh9/src:31:9: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
31 | pipe[i].h = m;
| ^
/tmp/compiler_zuw_wyh9/src:31:11: 错误:对成员‘h’的请求出现在‘*(pipe + ((sizetype)i))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
31 | pipe[i].h = m;
| ^
/tmp/compiler_zuw_wyh9/src:33:8: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
33 | pipe[n].l = 1;
| ^
/tmp/compiler_zuw_wyh9/src:33:10: 错误:对成员‘l’的请求出现在‘*(pipe + ((sizetype)n))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
33 | pipe[n].l = 1;
| ^
/tmp/compiler_zuw_wyh9/src:34:8: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
34 | pipe[n].h = m;
| ^
/tmp/compiler_zuw_wyh9/src:34:10: 错误:对成员‘h’的请求出现在‘*(pipe + ((sizetype)n))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
34 | pipe[n].h = m;
| ^
/tmp/compiler_zuw_wyh9/src:37:21: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
37 | std::cin >> pipe[p].l >> pipe[p].h;
| ^
/tmp/compiler_zuw_wyh9/src:37:23: 错误:对成员‘l’的请求出现在‘*(pipe + ((sizetype)p))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
37 | std::cin >> pipe[p].l >> pipe[p].h;
| ^
/tmp/compiler_zuw_wyh9/src:37:34: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
37 | std::cin >> pipe[p].l >> pipe[p].h;
| ^
/tmp/compiler_zuw_wyh9/src:37:36: 错误:对成员‘h’的请求出现在‘*(pipe + ((sizetype)p))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
37 | std::cin >> pipe[p].l >> pipe[p].h;
| ^
/tmp/compiler_zuw_wyh9/src:38:9: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
38 | pipe[p].l++;
| ^
/tmp/compiler_zuw_wyh9/src:38:11: 错误:对成员‘l’的请求出现在‘*(pipe + ((sizetype)p))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
38 | pipe[p].l++;
| ^
/tmp/compiler_zuw_wyh9/src:39:9: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
39 | pipe[p].h--;
| ^
/tmp/compiler_zuw_wyh9/src:39:11: 错误:对成员‘h’的请求出现在‘*(pipe + ((sizetype)p))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
39 | pipe[p].h--;
| ^
/tmp/compiler_zuw_wyh9/src:45:19: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
45 | if (j >= pipe[i].l && j <= pipe[i].h) {
| ^
/tmp/compiler_zuw_wyh9/src:45:21: 错误:对成员‘l’的请求出现在‘*(pipe + ((sizetype)i))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
45 | if (j >= pipe[i].l && j <= pipe[i].h) {
| ^
/tmp/compiler_zuw_wyh9/src:45:37: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
45 | if (j >= pipe[i].l && j <= pipe[i].h) {
| ^
/tmp/compiler_zuw_wyh9/src:45:39: 错误:对成员‘h’的请求出现在‘*(pipe + ((sizetype)i))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
45 | if (j >= pipe[i].l && j <= pipe[i].h) {
| ^
/tmp/compiler_zuw_wyh9/src:46:41: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
46 | if (j + touch[i - 1].y <= pipe[i - 1].h) {
| ^
cc1plus: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
/tmp/compiler_zuw_wyh9/src:46:43: 错误:对成员‘h’的请求出现在‘*(pipe + (((sizetype)i) + 18446744073709551615))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
46 | if (j + touch[i - 1].y <= pipe[i - 1].h) {
| ^
/tmp/compiler_zuw_wyh9/src:50:58: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
50 | for (int k = 1; j - k * touch[i - 1].x >= pipe[i - 1].l; k++) {
| ^
cc1plus: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
/tmp/compiler_zuw_wyh9/src:50:60: 错误:对成员‘l’的请求出现在‘*(pipe + (((sizetype)i) + 18446744073709551615))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
50 | for (int k = 1; j - k * touch[i - 1].x >= pipe[i - 1].l; k++) {
| ^
/tmp/compiler_zuw_wyh9/src:51:47: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
51 | if (j - k * touch[i - 1].x <= pipe[i - 1].h) {
| ^
cc1plus: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
/tmp/compiler_zuw_wyh9/src:51:49: 错误:对成员‘h’的请求出现在‘*(pipe + (((sizetype)i) + 18446744073709551615))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
51 | if (j - k * touch[i - 1].x <= pipe[i - 1].h) {
| ^
/tmp/compiler_zuw_wyh9/src:57:29: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
57 | for (int k = pipe[i - 1].l; k <= std::min(pipe[i - 1].h, m - 1); k++) {
| ^
cc1plus: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
/tmp/compiler_zuw_wyh9/src:57:31: 错误:对成员‘l’的请求出现在‘*(pipe + (((sizetype)i) + 18446744073709551615))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
57 | for (int k = pipe[i - 1].l; k <= std::min(pipe[i - 1].h, m - 1); k++) {
| ^
/tmp/compiler_zuw_wyh9/src:57:58: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
57 | for (int k = pipe[i - 1].l; k <= std::min(pipe[i - 1].h, m - 1); k++) {
| ^
cc1plus: 警告:在算术表达式中使用了函数指针 [-Wpointer-arith]
/tmp/compiler_zuw_wyh9/src:57:60: 错误:对成员‘h’的请求出现在‘*(pipe + (((sizetype)i) + 18446744073709551615))’中,而后者具有非类类型‘int(int*) noexcept’ {aka ‘int(int*)’}
57 | for (int k = pipe[i - 1].l; k <= std::min(pipe[i - 1].h, m - 1); k++) {
|