제출 #1055510

#제출 시각아이디문제언어결과실행 시간메모리
1055510c2zi6Carnival Tickets (IOI20_tickets)C++14
41 / 100
480 ms117972 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "tickets.h"

namespace TEST1 {
    ll find_maximum(int k, VVI table) {
        int n = table.size();
        int m = table[0].size();
        VI a;
        rep(i, n) a.pb(table[i][0]);
        sort(all(a));
        ll ans = 0;
        rep(i, n/2) ans -= a[i];
        rep(i, n/2) ans += a[i + n/2];
        VVI answ(n, VI(m, 0));
        allocate_tickets(answ);
        return ans;
    }
};
namespace TEST4 {
    struct CELL {
        int x, y, val;
    };
    bool operator<(const CELL& a, const CELL& b) {
        return a.val < b.val;
    }
    ll find_maximum(int k, VVI table) {
        int n = table.size();
        int m = table[0].size();
        vector<CELL> vec;
        rep(i, n) rep(j, m) {
            vec.pb({i, j, table[i][j]});
        }
        sort(all(vec));
        VVI a(n, VI(m, 1));
        rep(i, n*m/2) {
            auto[x, y, val] = vec[i];
            a[x][y] = 0;
        }
        ll ans = 0;
        VVI zro, mek;
        zro = mek = VVI(n);
        rep(i, n) {
            rep(j, m) {
                if (a[i][j]) {
                    mek[i].pb(j);
                    ans += table[i][j];
                } else {
                    zro[i].pb(j);
                    ans -= table[i][j];
                }
            }
        }
        VVI answ(n, VI(m, -1));
        rep(r, m) {
            VI round(n, -1);
            int cnt = 0;
            /* cnt(1) - cnt(0) */
            rep(i, n) {
                if (zro[i].size() == 0) {
                    round[i] = mek[i].back();
                    mek[i].pop_back();
                    cnt++;
                } else if (mek[i].size() == 0) {
                    round[i] = zro[i].back();
                    zro[i].pop_back();
                    cnt--;
                }
            }
            rep(i, n) if (round[i] == -1) {
                if (cnt > 0) {
                    round[i] = zro[i].back();
                    zro[i].pop_back();
                    cnt--;
                } else {
                    round[i] = mek[i].back();
                    mek[i].pop_back();
                    cnt++;
                }
            }
            rep(i, n) {
                int j = round[i];
                answ[i][j] = r;
            }
        }
        allocate_tickets(answ);
        return ans;
    }
};
namespace TEST2 {
    ll find_maximum(int k, VVI table) {
        int n = table.size();
        int m = table[0].size();
        ll ans = 0;
        VVI answ(n, VI(m, -1));
        VPL relax(n);
        rep(i, n) {
            relax[i] = {table[i][0] + table[i][m-1], i};
            ans -= table[i][0];
            answ[i][0] = 0;
        }
        sort(all(relax));
        reverse(all(relax));
        rep(_, n/2) {auto[profit, i] = relax[_];
            ans += profit;
            answ[i][0] = -1;
            answ[i][m-1] = 0;
        }
        allocate_tickets(answ);
        return ans;
    }
};

ll find_maximum(int k, VVI table) {
	int n = table.size();
	int m = table[0].size();
    if (m == 1) return TEST1::find_maximum(k, table);
    if (k == 1) return TEST2::find_maximum(k, table);
    if (m == k) return TEST4::find_maximum(k, table);
    return 0;
}











컴파일 시 표준 에러 (stderr) 메시지

tickets.cpp: In function 'll TEST4::find_maximum(int, VVI)':
tickets.cpp:66:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |             auto[x, y, val] = vec[i];
      |                 ^
tickets.cpp: In function 'll TEST2::find_maximum(int, VVI)':
tickets.cpp:133:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  133 |         rep(_, n/2) {auto[profit, i] = relax[_];
      |                          ^
tickets.cpp: In function 'll find_maximum(int, VVI)':
tickets.cpp:144:6: warning: unused variable 'n' [-Wunused-variable]
  144 |  int n = table.size();
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...