이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define int long long
const int nmax = 2e3 + 5, N = 1e5;
const ll oo = 1e12 + 1, base = 311;
const int lg = 19, M = 10;
const ll mod = 998244353, mod2 = 1e9 + 5277;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;
int n, L;
int a[nmax][nmax];
ll s[nmax][nmax];
struct node{
int x, y, id;
};
ll sum[nmax];
bool vis[nmax];
bool check(pii t1, pii t2){
return t1.fi * t2.se <= t1.se * t2.fi;
}
ll calc(int l, int r, int i){
if(l > r) return 0;
return s[i][r] - s[i][l - 1];
}
pii get(pii t1, pii t2, int idx){
if(t1.fi == 0) return t2;
if(t2.fi == 0) return t1;
pii tx ={t1.fi * t2.se + (t1.se * t2.fi * idx), t1.se * t2.se};
int lc = __gcd(tx.fi, tx.se);
return {tx.fi / lc, tx.se / lc};
}
pii c[nmax][nmax];
bool okla(pii t1, pii t2){
int lc = __gcd(t1.fi, t1.se);
t1.fi/= lc;
t1.se /= lc;
lc = __gcd(t2.fi, t2.se);
t2.fi /= lc;
t2.se /= lc;
return t1 == t2;
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("code.inp", "r", stdin);
// freopen("code.out", "w", stdout);
cin >> n >> L;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= L; ++j){
cin >> a[i][j];
sum[i] += a[i][j];
s[i][j] = s[i][j - 1] + a[i][j];
c[i][j] = {oo,1};
}
}
pii pos = {0, 0};
vector<int> tmp;
int last = 0;
for(int i = 1; i <= n; ++i){
last = 0;
for(int j = 1; j <= n; ++j){
int l =0, r = L, t1 = -1,t2 = -1;
l = 0, r = L + 1;
pii dx;
while(l <= r){
int mid = r + l >> 1;
pii tx = {0, 0};
tx = get(tx, {calc(1, mid, i), 1}, 1);
if(check(tx, {sum[i] * j, n})){
l = mid + 1;
t2 = mid;
dx = tx;
}
else r = mid - 1;
}
pii one = get({sum[i] * j, n}, dx, -1);
if(a[i][t2 + 1]) one.se *= a[i][t2 + 1];
pii tx = one;
tx = get(tx, {t2, 1}, 1);
c[i][j] = pos = tx;
}
}
pos = {0, 0};
for(int j = 1; j <= n; ++j){
int idx = -1;
pii ma;
for(int i = 1; i <= n; ++i){
if(vis[i]) continue;
if(idx == -1 || check(c[i][j], ma) && check(pos, c[i][j]) && !okla(pos, c[i][j])){
ma = c[i][j];
idx = i;
}
}
if(idx == -1) cout << -1, exit(0);
vis[idx] = 1;
if(j < n) cout << ma.fi << ' ' << ma.se << endl;
pos = ma;
tmp.push_back(idx);
}
for(auto p : tmp) cout << p << ' ';
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
antennas.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main(){
| ^~~~
antennas.cpp: In function 'int main()':
antennas.cpp:72:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
72 | int mid = r + l >> 1;
| ~~^~~
antennas.cpp:68:30: warning: unused variable 't1' [-Wunused-variable]
68 | int l =0, r = L, t1 = -1,t2 = -1;
| ^~
antennas.cpp:95:71: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
95 | if(idx == -1 || check(c[i][j], ma) && check(pos, c[i][j]) && !okla(pos, c[i][j])){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:64:9: warning: variable 'last' set but not used [-Wunused-but-set-variable]
64 | int last = 0;
| ^~~~
# | 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... |