이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "tickets.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pi = pair<ll, pair<ll, ll>>;
using ii = pair<int, int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
ll find_maximum(int K, vector<vector<int>> A) {
int N = A.size(), M = A[0].size();
deque<pi> curr; ll res = 0;
for(int l = 0; l < N; l++)
curr.pb({A[l][0], {l, 0}}),
curr.pb({A[l][M - 1], {l, M - 1}});
sort(curr.begin(), curr.end());
bool vis[N]; memset(vis, 0, sizeof vis);
vector<vector<int>> S(N, vector<int> (M, -1));
vector<ll> arr;
while(arr.size() != N) {
while(vis[curr.front().ss.ff])
curr.pop_front();
while(vis[curr.back().ss.ff])
curr.pop_back();
ll U = curr.front().ff;
ll V = curr.back().ff;
if(arr.empty()) {
arr.pb(curr.front().ff);
vis[curr.front().ss.ff] = 1;
S[curr.front().ss.ff][curr.front().ss.ss] = 0;
curr.pop_front();
continue;
}
sort(arr.begin(), arr.end());
ll md;
if((int)arr.size() & 1) md = arr[arr.size() / 2];
else md = (arr[arr.size() / 2] + arr[(arr.size() / 2) - 1]) / 2ll;
if(abs(U - md) > abs(V - md)) {
arr.pb(curr.front().ff);
vis[curr.front().ss.ff] = 1;
S[curr.front().ss.ff][curr.front().ss.ss] = 0;
curr.pop_front();
}
else {
arr.pb(curr.back().ff);
vis[curr.back().ss.ff] = 1;
S[curr.back().ss.ff][curr.back().ss.ss] = 0;
curr.pop_back();
}
}
sort(arr.begin(), arr.end());
for(auto U : arr)
res += abs(U - arr[N / 2]);
allocate_tickets(S);
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:30:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | while(arr.size() != N) {
| ~~~~~~~~~~~^~~~
# | 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... |