记录编号 199479 评测结果 AAAAA
题目名称 [NOI 1999]01串 最终得分 100
用户昵称 Gravatar啊吧啦吧啦吧 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2015-10-26 20:43:50 内存使用 0.35 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <climits>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8. typedef vector<long long> vll;
  9.  
  10. const long long MAXN(1010), INF(LLONG_MAX / 3);
  11. vll g[MAXN], c[MAXN];
  12. long long n, a0, b0, l0, a1, b1, l1, d[MAXN], gnq[MAXN] = {0};
  13. inline void addedge(long long, long long, long long), write();
  14. inline bool spfa(long long);
  15. queue<long long> q;
  16. bool inq[MAXN] = {false};
  17.  
  18. main() {
  19. freopen("sequence.in", "r", stdin);
  20. freopen("sequence.out", "w", stdout);
  21. cin >> n >> a0 >> b0 >> l0 >> a1 >> b1 >> l1;
  22. for (long long i = 0; i <= n; ++i) {
  23. addedge(n + 1, i, 0); //The number's dick exploded!
  24. if (i < n) {
  25. addedge(i + 1, i, 0);
  26. addedge(i, i + 1, 1);
  27. }
  28. if (i - l1 >= 0) {
  29. addedge(i - l1, i, b1);
  30. addedge(i, i - l1, -a1);
  31. }
  32. if (i - l0 >= 0) {
  33. addedge(i, i - l0, b0 - l0);
  34. addedge(i - l0, i, l0 - a0);
  35. }
  36. }
  37. if (spfa(n + 1))
  38. write();
  39. else
  40. cout << -1;
  41. // for (; ; );
  42. }
  43.  
  44. inline void addedge(long long fr, long long to, long long cst){
  45. g[fr].push_back(to);
  46. c[fr].push_back(cst);
  47. }
  48.  
  49. inline bool spfa(long long st) {
  50. q.push(st);
  51. inq[st] = true;
  52. ++gnq[st];
  53. fill(d, d + n + 2, INF);
  54. d[st] = 0;
  55. while (! q.empty()) {
  56. long long u = q.front();
  57. q.pop();
  58. inq[u] = false;
  59. for (long long i = 0; i < g[u].size(); ++i)
  60. if (d[g[u][i]] > d[u] + c[u][i]) {
  61. d[g[u][i]] = d[u] + c[u][i];
  62. if (! inq[g[u][i]]) {
  63. inq[g[u][i]] = true;
  64. ++gnq[g[u][i]];
  65. q.push(g[u][i]);
  66. if (gnq[g[u][i]] >= n + 1)
  67. return false;
  68. }
  69. }
  70. }
  71. return true;
  72. }
  73.  
  74. inline void write() {
  75. for (long long i = 1; i <= n; ++i)
  76. cout << d[i] - d[i - 1];
  77. }