QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462582#7793. 雷同swift0 1ms5676kbC++141.6kb2024-07-03 21:26:432024-07-03 21:26:43

Judging History

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

  • [2024-07-03 21:26:43]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5676kb
  • [2024-07-03 21:26:43]
  • 提交

answer

#include <bits/stdc++.h>
#define N 400
#define S 100
#define ll long long
using namespace std;
ll dp[N][N][S];
int T, n, w[N];
ll sum[N];
int main() {
  // freopen("a.in", "r", stdin);
  cin.tie(0)->sync_with_stdio(0);
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; i++)
      for (int j = i; j <= n; j++) {
        memset(dp[i][j], 0x3f, sizeof(dp[i][j]));
      }
    for (int i = 1; i <= n; i++)
      cin >> w[i], dp[i][i][0] = 0;
    sort(w + 1, w + n + 1);
    for (int i = 1; i <= n; i++)
      sum[i] = sum[i - 1] + w[i];
    for (int l = n; l >= 1; l--)
      for (int r = l + 1; r <= n; r++) {
        for (int i = __lg(r - l + 1); i <= r - l + 1 && i < S; i++) {
          vector<ll> tmp;
          for (int j = l; j < r; j++) {
            ll mi = LLONG_MAX;
            for (int k = max(__lg(r - j), i - 3); k < r - j && k < i; k++) {
              dp[l][r][i] =
                  min(dp[l][r][i], dp[l][j][i - 1] + dp[j + 1][r][k] +
                                       (1ll << k) - 1 + sum[r] - sum[l - 1]);
              mi = min(mi, dp[l][j][i - 1] + dp[j + 1][r][k] + (1ll << k) - 1 +
                               sum[r] - sum[l - 1]);
            }
            tmp.push_back(mi);
            /*for (int i = 0; i + 1 < tmp.size(); i++)
              cout << (tmp[i] < tmp[i + 1]) << " ";
            cout << endl;*/
          }
          if (i && dp[l][r][i] > dp[l][r][i - 1])
            break;
        }
      }
    cout << *min_element(dp[1][n], dp[1][n] + S) << '\n';
    // cout.flush();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5676kb

input:

4
6
1 3 5 7 9 11
6
2 4 6 8 10 12
6
100 1000 100 10 100 10
2
114514 1919810

output:

86
103
2781
2034324

result:

wrong answer 3rd words differ - expected: '1981', found: '2781'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Runtime Error

Test #39:

score: 0
Runtime Error

input:

2
2500
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #5:

0%