답안 #895496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895496 2023-12-30T05:42:59 Z hariaakas646 Group Photo (JOI21_ho_t3) C++17
100 / 100
691 ms 490632 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int main() {
    // usaco();
    int n;
    scd(n);

    vi vec(n+1);
    vi pos(n+1);

    forr(i, 1, n+1) {
        scd(vec[i]);
        pos[vec[i]] = i;
    }

    vector<vll> val(n+1, vll(n+1));
    vector<vll> val2(n+1, vll(n+1));
    vll pref(n+1);

    forr(i, 1, n+1) {
        forr(j, 1, n+1) {
            val[i][j] = val[i][j-1];
            // val2[i][j] = val2[i-1][j];
            if(pos[j] > pos[i]) {
                val[i][j]++;
                val2[i][j]++;
            }
        }
        pref[i] = pref[i-1] + val[i][i];
    }

    forr(i, 1, n+1) {
        forr(j, 1, n+1) {
            val2[i][j] = val2[i-1][j] + val[i][j];
        }
    }

    vvi cost(n+1, vi(n+1));
    forr(i, 1, n+1) {
        forr(j, i, n+1) {
            // forr(k, i, j+1) {
            //     cost[i][j] += val[k][i-1] + val[k][j] - val[k][k];
            // }
            cost[i][j] = val2[j][j] - val2[i-1][j] + val2[j][i-1] - val2[i-1][i-1] - (pref[j] - pref[i-1]); 
        }
    }

    vll dp(n+1, 1e17);
    dp[0] = 0;

    forr(i, 1, n+1) {
        frange(j, i) {
            dp[i] = min(dp[i], dp[j] + cost[j+1][i]);
        }
    }
    printf("%lld", dp[n]);
}

Compilation message

Main.cpp: In function 'void usaco()':
Main.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:37:5: note: in expansion of macro 'scd'
   37 |     scd(n);
      |     ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:43:9: note: in expansion of macro 'scd'
   43 |         scd(vec[i]);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1152 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1152 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 9 ms 12892 KB Output is correct
32 Correct 8 ms 12892 KB Output is correct
33 Correct 8 ms 12892 KB Output is correct
34 Correct 8 ms 12892 KB Output is correct
35 Correct 8 ms 13088 KB Output is correct
36 Correct 9 ms 12892 KB Output is correct
37 Correct 9 ms 13100 KB Output is correct
38 Correct 8 ms 12892 KB Output is correct
39 Correct 8 ms 12892 KB Output is correct
40 Correct 8 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1152 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 9 ms 12892 KB Output is correct
32 Correct 8 ms 12892 KB Output is correct
33 Correct 8 ms 12892 KB Output is correct
34 Correct 8 ms 12892 KB Output is correct
35 Correct 8 ms 13088 KB Output is correct
36 Correct 9 ms 12892 KB Output is correct
37 Correct 9 ms 13100 KB Output is correct
38 Correct 8 ms 12892 KB Output is correct
39 Correct 8 ms 12892 KB Output is correct
40 Correct 8 ms 12888 KB Output is correct
41 Correct 691 ms 489748 KB Output is correct
42 Correct 585 ms 490096 KB Output is correct
43 Correct 566 ms 490320 KB Output is correct
44 Correct 587 ms 490352 KB Output is correct
45 Correct 597 ms 490604 KB Output is correct
46 Correct 570 ms 490576 KB Output is correct
47 Correct 561 ms 490488 KB Output is correct
48 Correct 572 ms 490416 KB Output is correct
49 Correct 575 ms 490452 KB Output is correct
50 Correct 580 ms 490448 KB Output is correct
51 Correct 578 ms 490324 KB Output is correct
52 Correct 581 ms 490488 KB Output is correct
53 Correct 574 ms 490632 KB Output is correct
54 Correct 583 ms 490324 KB Output is correct
55 Correct 580 ms 490592 KB Output is correct