# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
889624 |
2023-12-20T04:02:38 Z |
vjudge1 |
Council (JOI23_council) |
C++17 |
|
268 ms |
15336 KB |
/*
author : abushbandit
contest : ---
*/
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
#define rep(i,s,f) for(int i = s;i < f;i++)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC optimize("Ofast,no-stack-protector,fast-math",3)
template <class type1>
using ordered_multiset = tree <type1, null_type, less_equal <type1>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
const ll INF = 1e18;
const ll MOD7 = 1e9 + 7;
const ll MOD9 = 998244353;
const ld PI = acos(-1.0);
const int N = 1e5 + 6;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
int binpow (int a, int n) {
int res = 1;
while (n) {
if (n & 1)
res *= a;
a *= a;
n >>= 1;
}
return res;
}
void start_file(string file){
freopen((file + ".in").c_str(),"r",stdin);
freopen((file + ".out").c_str(),"w",stdout);
}
void solve(int tc){
int n,m;
cin >> n >> m;
int a[n][m],s[m],b[n][m];
rep(i,0,n){
rep(j,0,m){
cin >> a[i][j];
b[i][j] = a[i][j];
}
}
if(n <= 3000 && m <= 3000){
rep(j,0,m){
int cnt = 0;
rep(i,0,n){
cnt += a[i][j] > 0;
}
s[j] = cnt;
// cout << s[j] << "\n";
}
rep(i,0,n){
rep(j,0,m){
a[i][j] = b[i][j];
}
}
for(int i = 0;i < n;i++){
int ans = 0;
for(int j = 0;j < n;j++){
if(i != j){
int cnt = 0;
for(int k = 0;k < m;k++){
// cout << s[k] << " ";
if(s[k] - ((a[i][k] == 1) + (a[j][k] == 1)) >= (n) / 2){
cnt++;
}
}
// cout << "\n";
ans = max(ans,cnt);
}
}
cout << ans << "\n";
}
} else if(m <= 2){
if(m == 1){
// rep(j,0,m){
// int cnt = 0;
// rep(i,0,n){
// cnt += a[i][j] > 0;
// }
// s[j] = cnt;
// // cout << s[j] << "\n";
// }
int cnt0 = 0,cnt1 = 0;
rep(i,0,n){
if(a[i][0] == 1){
cnt1++;
} else{
cnt0++;
}
}
rep(i,0,n){
int ans = 0;
if(a[i][0]== 1){
if(cnt0 > 0){
if(cnt1 - 1 >= (n / 2)){
ans = 1;
}
} else{
if(cnt1 - 2 >= (n / 2)){
ans = 1;
}
}
} else{
if(cnt0 - 1 > 0){
if(cnt1 >= (n / 2)){
ans = 1;
}
} else{
if(cnt1 - 1 >= (n / 2)){
ans = 1;
}
}
}
cout << ans << "\n";
}
} else{
rep(j,0,m){
int cnt = 0;
rep(i,0,n){
cnt += a[i][j] > 0;
}
s[j] = cnt;
// cout << s[j] << "\n";
}
vector<int> v00,v01,v10,v11;
for(int i = 0;i < n;i++){
if(a[i][0] == 0 && a[i][1] == 0){
v00.pb(i);
} else if(a[i][0] == 0 && a[i][1] == 1){
v01.pb(i);
} else if(a[i][0] == 1 && a[i][1] == 1){
v11.pb(i);
} else{
v10.pb(i);
}
}
for(int i = 0;i < n;i++){
int ans = 0;
if(v00.size() > 0 && v00[0] != i){
int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
ans = max(ans,h);
} else if(v00.size() > 1){
int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
ans = max(ans,h);
}
if(v01.size() > 0 && v01[0] != i){
int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
ans = max(ans,h);
} else if(v01.size() > 1){
int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
ans = max(ans,h);
}
if(v10.size() > 0 && v10[0] != i){
int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
ans = max(ans,h);
} else if(v10.size() > 1){
int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
ans = max(ans,h);
}
if(v11.size() > 0 && v11[0] != i){
int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
ans = max(ans,h);
} else if(v11.size() > 1){
int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
ans = max(ans,h);
}
cout << ans << "\n";
}
}
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// start_file("");
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int test_cases = 1;
// cin >> test_cases ;
for(int tc = 1;tc <= test_cases;++ tc){
solve(tc);
}
}
Compilation message
council.cpp: In function 'void solve(long long int)':
council.cpp:189:33: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
189 | int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:192:33: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
192 | int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:196:33: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
196 | int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:199:33: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
199 | int h = (s[0] - (a[i][0])) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:203:37: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
203 | int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:206:37: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
206 | int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1])) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:210:37: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
210 | int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:213:37: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
213 | int h = (s[0] - (a[i][0] + 1)) >= (n / 2) + (s[1] - (a[i][1] + 1)) >= (n / 2);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp: In function 'void start_file(std::string)':
council.cpp:75:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen((file + ".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:76:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | freopen((file + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
3 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 |
3 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 |
3 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 |
1 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 |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
548 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
3 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 |
3 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 |
3 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 |
1 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 |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
548 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
257 ms |
1368 KB |
Output is correct |
52 |
Correct |
249 ms |
1372 KB |
Output is correct |
53 |
Correct |
252 ms |
1624 KB |
Output is correct |
54 |
Correct |
268 ms |
1372 KB |
Output is correct |
55 |
Correct |
33 ms |
536 KB |
Output is correct |
56 |
Correct |
210 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
45 ms |
15336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
45 ms |
15336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
45 ms |
15336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
45 ms |
15336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
3 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 |
3 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 |
3 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 |
1 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 |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
548 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
257 ms |
1368 KB |
Output is correct |
52 |
Correct |
249 ms |
1372 KB |
Output is correct |
53 |
Correct |
252 ms |
1624 KB |
Output is correct |
54 |
Correct |
268 ms |
1372 KB |
Output is correct |
55 |
Correct |
33 ms |
536 KB |
Output is correct |
56 |
Correct |
210 ms |
1228 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Incorrect |
45 ms |
15336 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |