이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& in, pair<X,Y> &pr) {return in>>pr.first>>pr.second;}
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;}
template<typename X> istream& operator>>(istream& in, vector<X> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X> ostream& operator<<(ostream& os, vector<X> arr) {for(auto &it : arr) os<<it<<" "; return os;}
template<typename X, size_t Y> istream& operator>>(istream& in, array<X,Y> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> arr) {for(auto &it : arr) os<<it<<" "; return os;}
template<typename T> vector<int32_t> normalize(vector<T> &arr){vector<int32_t> rv;rv.resize(arr.size());for (long long i = 0; i < rv.size(); ++i){rv[i]=arr[i];}return rv;}
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
typedef long long ll;
#include "tickets.h"
long long find_maximum(int32_t k, vector<vector<int32_t>> _arr) {
int n = _arr.size();
int m = _arr[0].size();
vector<vector<ll>> arr(n,vector<ll>(m));
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
arr[i][j]=_arr[i][j];
}
}
int hed = k*((n+1)/2);
vector<vector<ll>> dp(n,vector<ll>(hed+1,-1));
vector<vector<ll>> pref = arr;
vector<vector<ll>> suff = arr;
for (int i = 0; i < n; i++){
for (int j = 1; j < m; j++){
pref[i][j]+=pref[i][j-1];
}
for (int j = m-2; j >= 0; j--){
suff[i][j]+=suff[i][j+1];
}
}
function<ll(int,int)> bastan = [&](int i, int j){
if (j==0) return 0ll;
return pref[i][j-1];
};
function<ll(int,int)> sondan = [&](int i, int j){
if (j==0) return 0ll;
return suff[i][m-j];
};
function<ll(int,int)> f;
vector<vector<int>> way(n,vector<int>(hed+1,-1));
f = [&](int node, int flag)->ll{
if (node==n) {
if (flag) return -23;
return 0;
}
if (dp[node][flag]!=-1) return dp[node][flag];
dp[node][flag]=-23;
for (int i = 0; i <= min(k,flag); i++){
if (f(node+1,flag-i)==-23) continue;
ll crr = f(node+1,flag-i)+(sondan(node,k-i)-bastan(node,i));
if (crr>dp[node][flag]){
dp[node][flag]=crr;
way[node][flag]=i;
}
}
return dp[node][flag];
};
vector<vector<int>> rval(n,vector<int>(m,-1));
ll ans = f(0,hed);
vector<int> crr(n);
for (int node = 0; node < n; node++){
crr[node]=way[node][hed];
hed-=way[node][hed];
}
vector<int> kucuk(k,n/2);
vector<int> buyuk(k,n/2);
set<int> avak;
set<int> avab;
for (int i = 0; i < k; ++i)
{
avak.insert(i);
avab.insert(i);
}
for (int i = 0; i < n; i++){
set<int> kul;
for (int j = 0; j < crr[i]; j++){
rval[i][j]=*avak.begin();
kul.insert(rval[i][j]);
kucuk[rval[i][j]]--;
avak.erase(rval[i][j]);
avab.erase(rval[i][j]);
}
for (int j = m-1; j >= m-(k-crr[i]); j--){
rval[i][j]=*avab.begin();
kul.insert(rval[i][j]);
buyuk[rval[i][j]]--;
avab.erase(rval[i][j]);
}
while (kul.size()){
int node = *kul.begin();
kul.erase(node);
if (buyuk[node]>0) avab.insert(node);
if (kucuk[node]>0) avak.insert(node);
}
}
allocate_tickets(rval);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
1 | #pragma optimize("Bismillahirrahmanirrahim")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |