QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405943#8225. 最小值之和juicy_name0 2ms8812kbC++144.1kb2024-05-06 17:27:192024-05-06 17:27:20

Judging History

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

  • [2024-05-06 17:27:20]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:8812kb
  • [2024-05-06 17:27:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int n;
int f[maxn];
int p[85][85][85];
void exgcd(int a, int b, int &x, int &y){
    if(b == 0){
        x = 0; y = 1; return ;
    }
    exgcd(b, a % b, y, x); y -= a / b * x; return ;
}
int tp[6405]; int tc[85];
int tk[85];
pair<int, int> pc[85][85][85];
bool vis[85][85];
bool vs[85];
void dfs(int l, int r){
    if(vis[l][r]) return ;
    vis[l][r] = 1;
    if(l == r){
        if(f[l] == f[l + 1]) p[l][r][0] = f[l];
        return ;
    }
    int N = r - l + 1;
    for(int i = l;i <= r;i++){
        if(i == l){
            dfs(i + 1, r);
            if(p[i + 1][r][f[l] % (N - 1)] < f[l]) continue;
            p[l][r][f[l] % N] = max(p[l][r][f[l] % N], f[l]); continue;
        }
        if(i == r){
            dfs(l, i - 1);
            if(p[l][i - 1][f[r + 1] % (N - 1)] < f[r + 1]) continue;
            p[l][r][f[r + 1] % N] = max(p[l][r][f[r + 1] % N], f[r + 1]); continue;
        }
        dfs(l, i - 1); dfs(i + 1, r);
        int L = i - l; int R = r - i;
        int pg = __gcd(L, R); int pN = L * R / pg;
        int tx = 0, ty = 0; exgcd(L, R, tx, ty); int pR = R / pg;
        tx = (tx % pR + pR) % pR;
        for(int j = 0;j < pN;j++) tp[j] = -1;
        for(int j = 0;j < L;j++){
            if(p[l][i - 1][j] < 0) continue;
            for(int k = 0;k < R;k++){
                if(p[i + 1][r][k] < 0) continue;
                if(j % pg != k % pg) continue;
                int px = 1ll * (k - j) * tx % pR; px = (px + pR) % pR; 
                int pmi = min(p[l][i - 1][j], p[i + 1][r][k]);
                int pnum = L * px + j;
                if(pnum > pmi) continue;
                tp[pnum] = max(tp[pnum], pnum + (pmi - pnum) / pN * pN);
            }
        }
        for(int j = 0;j < N;j++) tc[j] = -1;
        for(int j = 0;j < pN;j++){
            if(tp[j] == -1) continue;
            tc[j % N] = max(tc[j % N], tp[j]);
        }
        for(int j = 0;j < N;j++){
            tk[j] = tc[j]; vs[j] = 0;
        }
        int x = (N - pN % N) % N;
        for(int j = 0;j < N;j++){
            if(vs[j]) continue;
            int now = j;
            do{
                if(tc[now] - pN > tc[(now + x) % N]){
                    tk[(now + x) % N] = tk[now]; tc[(now + x) % N] = tc[now] - pN;
                }
                vs[now] = 1; now = (now + x) % N;
            }while(now != j);
            do{
                if(tc[now] - pN > tc[(now + x) % N]){
                    tk[(now + x) % N] = tk[now]; tc[(now + x) % N] = tc[now] - pN;
                }
                now = (now + x) % N;
            }while(now != j);
        }
        for(int j = 0;j < N;j++){
            if(tc[j] > p[l][r][j]){
                p[l][r][j] = tc[j]; pc[l][r][j] = make_pair(tk[j], i);
            }
        }
    }
    // cerr << l << " " << r << endl << "? ";
    // for(int i = 0;i < N;i++){
    //     cerr << p[l][r][i] << " ";
    // }
    // cerr << endl;
    return ;
}
int ans[maxn];
void dfsp(int l, int r, int num, int res){
    if(l == r){
        ans[l] = f[l] - num + res; return ;
    }
    int N = r - l + 1;
    if(p[l + 1][r][f[l] % (N - 1)] >= f[l]){
        ans[l] = (f[l] - num) / N + res; dfsp(l + 1, r, f[l], ans[l]); return ;
    }
    if(p[l][r - 1][f[r + 1] % (N - 1)] >= f[r + 1]){
        ans[r] = (f[r + 1] - num) / N + res; dfsp(l, r - 1, f[r + 1], ans[r]); return ;
    }
    int pos = pc[l][r][num % N].second;
    ans[pos] = (pc[l][r][num % N].first - num) / N + res;
    dfsp(l, pos - 1, pc[l][r][num % N].first, ans[pos]);
    dfsp(pos + 1, r, pc[l][r][num % N].first, ans[pos]);
    return ;
}   
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> f[i];
    }
    memset(p, -1, sizeof(p));
    dfs(1, n - 1);
    if(p[1][n - 1][0] < 0){
        cout << "No" << endl; return 0;
    }
    dfsp(1, n - 1, 0, 0);
    cout << "Yes" << '\n';
    for(int i = 1;i < n;i++){
        cout << ans[i] << " ";
    }
    cout << '\n';
    cout.flush(); return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 11
Accepted
time: 1ms
memory: 7632kb

input:

5
14 14 12 13 13

output:

Yes
5 3 3 4 

result:

ok The answer is correct.

Test #2:

score: 11
Accepted
time: 0ms
memory: 6384kb

input:

5
4 4 7 7 4

output:

Yes
1 1 4 1 

result:

ok The answer is correct.

Test #3:

score: 11
Accepted
time: 1ms
memory: 7684kb

input:

5
4 13 14 14 13

output:

Yes
1 4 5 4 

result:

ok The answer is correct.

Test #4:

score: 11
Accepted
time: 1ms
memory: 6160kb

input:

5
11 11 10 5 5

output:

Yes
5 4 1 2 

result:

ok The answer is correct.

Test #5:

score: 11
Accepted
time: 1ms
memory: 6372kb

input:

5
10 10 10 4 4

output:

Yes
4 4 1 1 

result:

ok The answer is correct.

Test #6:

score: 11
Accepted
time: 1ms
memory: 6464kb

input:

5
20 20 17 7 4

output:

Yes
10 7 2 1 

result:

ok The answer is correct.

Test #7:

score: 11
Accepted
time: 2ms
memory: 8812kb

input:

5
12 12 16 19 19

output:

Yes
3 3 5 8 

result:

ok The answer is correct.

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 6480kb

input:

5
2 2 6 11 11

output:

Yes
0 0 2 7 

result:

wrong answer Your answer is wrong.

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%