답안 #720025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720025 2023-04-07T09:17:28 Z khanhhdz191 Group Photo (JOI21_ho_t3) C++14
100 / 100
423 ms 196352 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn=  5002;
const ll base=3e18;
const ll mod= 1e9+7 ;
/// goal 4/8
ll pos[maxn];
ll dp[maxn];
ll sum[maxn][maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen("cheetos.inp","r"))
    {
        freopen("cheetos.in","r",stdin);
        freopen("cheetos.out","w",stdout);
    }
     ll n;
     cin>> n;
     for (int i=1; i<=n; i++)
     {
        ll x;
        cin>> x;
        pos[x]=i;
     }
    ll ans=0;
    for (int i=1; i<=n; i++)
    for (int j=1; j<i; j++)
    {
       if (pos[j]>pos[i]) ans++;
    }
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
        {
            if (i<j&&pos[i]>pos[j]) sum[i][j]--;
            if (i<j&&pos[i]<pos[j]) sum[i][j]++;
            sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
        }
    for (int i=1; i<=n; i++)
    {
        dp[i]=base;
        for (int j=0; j<i; j++)
        {
            dp[i]=min(dp[i],dp[j]+sum[i][i]+sum[j][j]-sum[i][j]-sum[j][i]);
        }
    }
    ans+=dp[n];
    cout <<ans;


}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen("cheetos.in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("cheetos.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 1 ms 1364 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 2 ms 1348 KB Output is correct
25 Correct 1 ms 1364 KB Output is correct
26 Correct 2 ms 1364 KB Output is correct
27 Correct 2 ms 1364 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 2 ms 1364 KB Output is correct
30 Correct 2 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 1 ms 1364 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 2 ms 1348 KB Output is correct
25 Correct 1 ms 1364 KB Output is correct
26 Correct 2 ms 1364 KB Output is correct
27 Correct 2 ms 1364 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 2 ms 1364 KB Output is correct
30 Correct 2 ms 1364 KB Output is correct
31 Correct 9 ms 8524 KB Output is correct
32 Correct 11 ms 8516 KB Output is correct
33 Correct 9 ms 8504 KB Output is correct
34 Correct 10 ms 8532 KB Output is correct
35 Correct 10 ms 8532 KB Output is correct
36 Correct 9 ms 8608 KB Output is correct
37 Correct 9 ms 8520 KB Output is correct
38 Correct 10 ms 8520 KB Output is correct
39 Correct 10 ms 8532 KB Output is correct
40 Correct 10 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 1 ms 1364 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 2 ms 1348 KB Output is correct
25 Correct 1 ms 1364 KB Output is correct
26 Correct 2 ms 1364 KB Output is correct
27 Correct 2 ms 1364 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 2 ms 1364 KB Output is correct
30 Correct 2 ms 1364 KB Output is correct
31 Correct 9 ms 8524 KB Output is correct
32 Correct 11 ms 8516 KB Output is correct
33 Correct 9 ms 8504 KB Output is correct
34 Correct 10 ms 8532 KB Output is correct
35 Correct 10 ms 8532 KB Output is correct
36 Correct 9 ms 8608 KB Output is correct
37 Correct 9 ms 8520 KB Output is correct
38 Correct 10 ms 8520 KB Output is correct
39 Correct 10 ms 8532 KB Output is correct
40 Correct 10 ms 8532 KB Output is correct
41 Correct 401 ms 196144 KB Output is correct
42 Correct 359 ms 196244 KB Output is correct
43 Correct 408 ms 196120 KB Output is correct
44 Correct 380 ms 196188 KB Output is correct
45 Correct 377 ms 196144 KB Output is correct
46 Correct 415 ms 196300 KB Output is correct
47 Correct 376 ms 196180 KB Output is correct
48 Correct 380 ms 196176 KB Output is correct
49 Correct 423 ms 196204 KB Output is correct
50 Correct 408 ms 196352 KB Output is correct
51 Correct 402 ms 196188 KB Output is correct
52 Correct 401 ms 196080 KB Output is correct
53 Correct 375 ms 196184 KB Output is correct
54 Correct 393 ms 196196 KB Output is correct
55 Correct 385 ms 196168 KB Output is correct