QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#954509#10220. Picturesque SkylineHuTaoWA 213ms3840kbC++141.5kb2025-03-28 21:26:212025-03-28 21:26:22

Judging History

This is the latest submission verdict.

  • [2025-03-28 21:26:22]
  • Judged
  • Verdict: WA
  • Time: 213ms
  • Memory: 3840kb
  • [2025-03-28 21:26:21]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1005, INF = 0x3f3f3f3f;

int n, a[N];
int fl[N], fr[N];
int buf[N * 2], *cnt = buf + N;
int f[N];

inline void Solve()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
    for(int i = 1; i <= n; i ++ ) f[i] = INF;
    f[0] = 0;
    for(int i = 2; i < n; i ++ )
    {
        for(int j = 1; j <= n; j ++ ) fl[j] = fr[j] = 0;
        for(int l = i - 1, r = i + 1; l >= 1 && r <= n; l -- , r ++ )
        {
            for(int i = l + 1; i < r; i ++ )
            {
                fl[i] += a[i] < a[l];
                fr[i] += a[i] < a[r];
                fr[l] += a[l] < a[i];
                fl[r] += a[r] < a[i];
            }
            int w = 0;
            for(int i = -(r - l + 1); i <= (r - l + 1); i ++ )
            {
                cnt[i] = 0;
            }
            for(int i = l; i <= r; i ++ )
            {
                w += fl[i];
                cnt[fr[i] - fl[i]] ++ ;
            }
            cnt[0] -- ;
            int k = r - i;
            for(int i = -(r - l + 1); i <= (r - l + 1) && k; i ++ )
            {
                cnt[i] = min(cnt[i], k);
                w += i * cnt[i];
                k -= cnt[i];
            }
            // printf("![%d %d] -> %d\n", l, r, w);
            if(w > n / 3 + 10) break;
            f[r] = min(f[r], f[l - 1] + w);
        }
    }
    printf("%d\n", f[n]);
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T -- ) Solve();
    return 0;
}

詳細信息

Test #1:

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

input:

4
3
1 3 2
6
1 2 4 8 16 32
5
1 2 3 4 5
7
6 4 2 1 3 5 7

output:

0
2
3
9

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 213ms
memory: 3840kb

input:

10
1000
1387006 1849130 3142445 4286557 8454496 12729744 12851090 12922927 13529136 13801515 16497484 18988046 22387865 22451673 22964870 24979445 27172325 35553226 38233807 40309279 43222378 45411991 45480206 51693604 51853974 57504350 64692967 67181740 70422962 73141342 76819930 76823620 77987836 ...

output:

0
0
8
8
17
15
44
43
126
126

result:

wrong answer 8th lines differ - expected: '44', found: '43'