QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376853#3170. Lunchtime Name Recallckiseki#AC ✓3018ms5676kbC++202.9kb2024-04-04 17:41:052024-04-04 17:41:05

Judging History

你现在查看的是最新测评结果

  • [2024-04-04 17:41:05]
  • 评测
  • 测评结果:AC
  • 用时:3018ms
  • 内存:5676kb
  • [2024-04-04 17:41:05]
  • 提交

answer

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << "\n";
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);


  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++)
    cin >> a[i];


  set<long long> dp[11];

  vector<long long> wei(n + 1, 1);
  wei[0] = n;
  for (int i = 1; i <= n; i++) {
    wei[i] = n / i + 1;
  }

  vector<long long> prewei(n + 1, 1);
  for (int i = 1; i <= n; i++)
    prewei[i] = prewei[i - 1] * wei[i - 1];

  orange(all(wei));
  orange(all(prewei));

  dp[0].insert(prewei[n]);

  auto decode = [&](long long enc_v) {
    vector<int> v;
    for (int j = 1; j <= n; j++) {
      int c = enc_v / prewei[j] % wei[j];
      for (int t = 0; t < c; t++)
        v.push_back(j);
    }
    return v;
  };

  // auto v = decode(prewei[n]);
  // orange(all(v));
  // return 0;

  vector<long long> cur[31], nxt[31];

  for (int i = 0; i < m; i++) {
    for (auto enc_v : dp[i]) {

      auto v = decode(enc_v);

      for (int j = 0; j <= a[i]; j++)
        cur[j].clear();

      cur[0].push_back(0);

      // vector<size_t> sizes;
      for (size_t j = 0; j < v.size(); j++) {
        for (int x = 0; x <= a[i]; x++)
          nxt[x].clear();

        for (int y = 0; y <= v[j]; y++) {
          for (int x = 0; x + y <= a[i]; x++) {
            for (auto u : cur[x]) {
              if (y)
                u += prewei[y];
              if (v[j] - y)
                u += prewei[v[j] - y];
              // if (y)
              //   u.push_back(y);
              // if (v[j] - y)
              //   u.push_back(v[j] - y);
              // sort(all(u));
              nxt[x + y].push_back(u);
            }
          }
        }

        for (int x = 0; x <= a[i]; x++) {
          cur[x] = nxt[x];
          sort(all(cur[x]));
          cur[x].erase(unique(all(cur[x])), end(cur[x]));
        }
        // size_t s = 0;
        // for (int x = 0; x <= a[i]; x++)
        //   s += cur[x].size();
        // sizes.push_back(s);
      }

      for (auto u : cur[a[i]]) {
        dp[i + 1].insert(u);
      }
    }
    debug(dp[i].size());
  }

  debug(dp[m].size());

  int ans = 0;
  for (auto enc_v : dp[m]) {
    auto v = decode(enc_v);
    int cnt = 0;
    for (int x : v)
      if (x == 1)
        ++cnt;
    ans = max(ans, cnt);
  }
  cout << ans << '\n';

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

20 7
1
1
1
1
6
8
8

output:

11

result:

ok single line: '11'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

7 3
3
2
1

output:

4

result:

ok single line: '4'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

9 4
1
1
3
3

output:

5

result:

ok single line: '5'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

10 3
4
4
3

output:

6

result:

ok single line: '6'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

10 3
4
4
5

output:

6

result:

ok single line: '6'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

10 3
4
4
4

output:

7

result:

ok single line: '7'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

12 3
6
6
6

output:

6

result:

ok single line: '6'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

10 5
2
2
2
2
2

output:

7

result:

ok single line: '7'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

10 6
2
2
2
2
2
2

output:

10

result:

ok single line: '10'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

10 2
3
3

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

10 6
8
5
2
8
8
1

output:

10

result:

ok single line: '10'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

7 4
5
5
1
2

output:

5

result:

ok single line: '5'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

2 1
1

output:

2

result:

ok single line: '2'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

3 1
1

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

30 1
15

output:

0

result:

ok single line: '0'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

3 5
1
1
1
1
1

output:

3

result:

ok single line: '3'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

5 6
2
2
2
2
2
2

output:

5

result:

ok single line: '5'

Test #22:

score: 0
Accepted
time: 191ms
memory: 4028kb

input:

30 5
15
15
15
15
13

output:

28

result:

ok single line: '28'

Test #23:

score: 0
Accepted
time: 243ms
memory: 4800kb

input:

30 10
15
15
15
15
15
1
1
1
1
1

output:

30

result:

ok single line: '30'

Test #24:

score: 0
Accepted
time: 183ms
memory: 5156kb

input:

30 10
15
10
10
10
10
1
1
1
1
1

output:

28

result:

ok single line: '28'

Test #25:

score: 0
Accepted
time: 220ms
memory: 4572kb

input:

30 7
9
9
9
9
9
9
2

output:

28

result:

ok single line: '28'

Test #26:

score: 0
Accepted
time: 471ms
memory: 4304kb

input:

30 10
2
2
2
3
3
3
6
11
14
15

output:

28

result:

ok single line: '28'

Test #27:

score: 0
Accepted
time: 310ms
memory: 4316kb

input:

30 10
1
2
3
4
5
6
7
8
9
10

output:

30

result:

ok single line: '30'

Test #28:

score: 0
Accepted
time: 2600ms
memory: 5416kb

input:

30 10
11
12
13
14
15
16
17
18
19
20

output:

30

result:

ok single line: '30'

Test #29:

score: 0
Accepted
time: 3018ms
memory: 5336kb

input:

30 10
20
21
22
23
24
25
26
27
28
29

output:

30

result:

ok single line: '30'

Test #30:

score: 0
Accepted
time: 70ms
memory: 4116kb

input:

30 10
4
4
4
5
5
5
5
5
5
5

output:

28

result:

ok single line: '28'

Test #31:

score: 0
Accepted
time: 266ms
memory: 4244kb

input:

30 10
2
2
2
3
3
3
8
8
9
11

output:

28

result:

ok single line: '28'

Test #32:

score: 0
Accepted
time: 223ms
memory: 4300kb

input:

30 10
2
2
2
3
3
3
9
9
9
9

output:

28

result:

ok single line: '28'

Test #33:

score: 0
Accepted
time: 66ms
memory: 5040kb

input:

30 10
12
12
12
12
3
2
2
2
2
2

output:

28

result:

ok single line: '28'

Test #34:

score: 0
Accepted
time: 68ms
memory: 5188kb

input:

30 10
10
9
9
9
3
3
2
2
2
2

output:

28

result:

ok single line: '28'

Test #35:

score: 0
Accepted
time: 81ms
memory: 5028kb

input:

30 10
10
9
9
8
5
2
2
2
2
2

output:

28

result:

ok single line: '28'

Test #36:

score: 0
Accepted
time: 109ms
memory: 5152kb

input:

30 10
9
9
9
8
8
3
2
2
1
1

output:

28

result:

ok single line: '28'

Test #37:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

30 10
1
1
1
1
1
1
1
1
1
1

output:

10

result:

ok single line: '10'

Test #38:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

30 10
2
2
2
2
2
2
2
2
2
2

output:

15

result:

ok single line: '15'

Test #39:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

30 10
3
3
3
3
3
3
3
3
3
3

output:

20

result:

ok single line: '20'

Test #40:

score: 0
Accepted
time: 15ms
memory: 4088kb

input:

30 10
4
4
4
4
4
4
4
4
4
4

output:

25

result:

ok single line: '25'

Test #41:

score: 0
Accepted
time: 65ms
memory: 4388kb

input:

30 10
5
5
5
5
5
5
5
5
5
5

output:

30

result:

ok single line: '30'

Test #42:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

30 3
2
2
2

output:

4

result:

ok single line: '4'

Test #43:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

30 6
2
2
2
2
2
2

output:

9

result:

ok single line: '9'

Test #44:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

30 9
2
2
2
2
2
2
2
2
2

output:

13

result:

ok single line: '13'

Test #45:

score: 0
Accepted
time: 88ms
memory: 4156kb

input:

30 10
2
3
4
5
5
5
5
5
6
6

output:

28

result:

ok single line: '28'

Test #46:

score: 0
Accepted
time: 76ms
memory: 4228kb

input:

30 10
2
4
5
5
5
5
5
5
5
6

output:

28

result:

ok single line: '28'

Test #47:

score: 0
Accepted
time: 2049ms
memory: 4816kb

input:

30 10
15
15
15
15
29
29
29
29
29
29

output:

20

result:

ok single line: '20'

Test #48:

score: 0
Accepted
time: 225ms
memory: 4048kb

input:

30 5
15
15
15
15
15

output:

30

result:

ok single line: '30'

Test #49:

score: 0
Accepted
time: 110ms
memory: 4584kb

input:

30 10
3
6
6
7
4
3
5
3
6
4

output:

28

result:

ok single line: '28'

Test #50:

score: 0
Accepted
time: 102ms
memory: 4724kb

input:

30 10
5
2
6
7
4
7
3
4
2
6

output:

28

result:

ok single line: '28'

Test #51:

score: 0
Accepted
time: 2370ms
memory: 5588kb

input:

30 10
20
6
20
19
11
18
21
24
18
12

output:

30

result:

ok single line: '30'

Test #52:

score: 0
Accepted
time: 2162ms
memory: 5676kb

input:

30 10
7
22
8
12
12
23
10
11
24
21

output:

30

result:

ok single line: '30'

Test #53:

score: 0
Accepted
time: 2064ms
memory: 5316kb

input:

30 10
19
21
23
17
8
21
15
20
6
22

output:

30

result:

ok single line: '30'

Test #54:

score: 0
Accepted
time: 1239ms
memory: 5456kb

input:

30 10
16
5
19
16
10
14
10
12
14
4

output:

30

result:

ok single line: '30'

Test #55:

score: 0
Accepted
time: 2251ms
memory: 5344kb

input:

30 10
5
9
7
10
6
21
15
24
17
21

output:

30

result:

ok single line: '30'

Test #56:

score: 0
Accepted
time: 64ms
memory: 4416kb

input:

30 10
2
4
7
3
2
6
7
2
5
2

output:

25

result:

ok single line: '25'

Test #57:

score: 0
Accepted
time: 161ms
memory: 4508kb

input:

30 10
8
6
4
2
2
3
4
8
6
5

output:

30

result:

ok single line: '30'

Test #58:

score: 0
Accepted
time: 116ms
memory: 4460kb

input:

30 10
6
4
6
4
5
2
3
3
5
8

output:

28

result:

ok single line: '28'

Test #59:

score: 0
Accepted
time: 107ms
memory: 4928kb

input:

30 10
4
12
8
13
8
1
1
1
1
1

output:

24

result:

ok single line: '24'

Test #60:

score: 0
Accepted
time: 276ms
memory: 5296kb

input:

30 10
7
13
6
9
14
1
1
1
1
1

output:

25

result:

ok single line: '25'

Test #61:

score: 0
Accepted
time: 146ms
memory: 5040kb

input:

30 10
5
11
8
14
9
1
1
1
1
1

output:

25

result:

ok single line: '25'

Test #62:

score: 0
Accepted
time: 36ms
memory: 4732kb

input:

30 10
4
12
5
12
1
3
1
2
1
3

output:

22

result:

ok single line: '22'

Test #63:

score: 0
Accepted
time: 49ms
memory: 4936kb

input:

30 10
6
13
12
10
1
2
1
2
1
1

output:

21

result:

ok single line: '21'

Test #64:

score: 0
Accepted
time: 37ms
memory: 4588kb

input:

30 10
7
5
14
5
1
3
2
3
2
2

output:

24

result:

ok single line: '24'

Test #65:

score: 0
Accepted
time: 375ms
memory: 4428kb

input:

30 5
12
14
15
12
15

output:

27

result:

ok single line: '27'

Test #66:

score: 0
Accepted
time: 253ms
memory: 4152kb

input:

30 5
14
13
15
11
11

output:

26

result:

ok single line: '26'

Test #67:

score: 0
Accepted
time: 308ms
memory: 4148kb

input:

30 5
13
12
14
11
12

output:

26

result:

ok single line: '26'

Test #68:

score: 0
Accepted
time: 329ms
memory: 4320kb

input:

30 6
11
10
9
9
10
9

output:

28

result:

ok single line: '28'

Test #69:

score: 0
Accepted
time: 277ms
memory: 4264kb

input:

30 6
10
7
8
11
9
9

output:

27

result:

ok single line: '27'

Test #70:

score: 0
Accepted
time: 265ms
memory: 4288kb

input:

30 6
7
9
8
10
10
8

output:

26

result:

ok single line: '26'

Test #71:

score: 0
Accepted
time: 299ms
memory: 4384kb

input:

30 7
6
10
7
9
6
8
9

output:

30

result:

ok single line: '30'

Test #72:

score: 0
Accepted
time: 293ms
memory: 4672kb

input:

30 7
7
6
7
10
7
7
10

output:

30

result:

ok single line: '30'

Test #73:

score: 0
Accepted
time: 187ms
memory: 4296kb

input:

30 7
7
8
6
8
8
7
6

output:

28

result:

ok single line: '28'

Test #74:

score: 0
Accepted
time: 171ms
memory: 4512kb

input:

30 10
2
2
4
5
8
5
4
11
3
3

output:

28

result:

ok single line: '28'

Test #75:

score: 0
Accepted
time: 120ms
memory: 4388kb

input:

30 9
5
2
3
3
8
10
6
3
6

output:

27

result:

ok single line: '27'

Test #76:

score: 0
Accepted
time: 44ms
memory: 4304kb

input:

30 9
5
2
3
3
8
8
4
3
3

output:

24

result:

ok single line: '24'

Test #77:

score: 0
Accepted
time: 130ms
memory: 4568kb

input:

30 10
3
2
6
4
1
8
4
8
4
6

output:

28

result:

ok single line: '28'

Test #78:

score: 0
Accepted
time: 116ms
memory: 4576kb

input:

30 9
3
6
6
11
2
7
4
2
6

output:

27

result:

ok single line: '27'

Test #79:

score: 0
Accepted
time: 125ms
memory: 4592kb

input:

30 10
3
8
6
5
2
7
4
2
2
7

output:

28

result:

ok single line: '28'

Test #80:

score: 0
Accepted
time: 154ms
memory: 4408kb

input:

30 9
3
6
4
2
7
8
5
8
4

output:

28

result:

ok single line: '28'

Test #81:

score: 0
Accepted
time: 119ms
memory: 4648kb

input:

30 9
8
7
6
4
7
2
5
6
2

output:

28

result:

ok single line: '28'

Test #82:

score: 0
Accepted
time: 126ms
memory: 4296kb

input:

30 10
3
5
2
7
7
1
6
2
6
7

output:

28

result:

ok single line: '28'

Test #83:

score: 0
Accepted
time: 71ms
memory: 4328kb

input:

30 9
2
3
2
3
4
8
15
3
5

output:

24

result:

ok single line: '24'