답안 #1088012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088012 2024-09-13T17:09:16 Z guymmk Izbori (COCI17_izbori) C++14
42 / 80
184 ms 600 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("popcnt")
#define int long long
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define debug(...) printf(__VA_ARGS__)
//#define debug(...)
#define trace(x) cout<<#x<<"="<<x<<endl;
//#define trace(x)
#define vi vector<int>
#define popcnt(x) __builtin_popcount(x)
#define vpii vector<pii >
#define vvi vector<vector<int> >
#define umap unordered_map
#define uset unordered_set
#define mk make_pair
#define pb push_back
#define pob pop_back
#define _ <<' '<<
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define read(x) for (auto& zu: (x)) cin >> zu;

static inline void print(const int &x) {
    if (x > 9)print(x / 10);
    putchar('0' + x % 10);
}

#define F first
#define S second
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define mustawa ios::sync_with_stdio(false);cin.tie(nullptr);

#define mishari main
const int inf=1e9+7;
void fa(bool ok){ cout << (ok ? "YES": "NO") << endl;}
int pw(ll a, ll b, ll mod= 1e9 + 7){
    ll result = 1;
    while(b) {
        if(b&1) {
            result = (result*a)%mod;
        }
        a = (a * a) % mod;
        b>>=1;
    }
    return result;
}
inline void usaco(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}int gcd(int a,int b){
    if (b == 0)return a;
    return gcd(b, a % b);
}

int lcm(int a, int b){
    return (a / gcd(a, b)) * b;
}
//long double log(int base,int x){
//    return log2(x)/log(base);
//}
int log(int base,int x){
    return ceil(log2(x)/log(base));
}
void vod(){}
int sum(int l,int r){
    int a=((l-1)*(l))/2;
    int b=(r*(r+1))/2;
    return b-a;
}struct DSU {
    vi par, size;

    void init(int n) {
        par.resize(n + 1);
        size.resize(n + 1, 1);
        iota(all(par), 0);
    }

    int find(int v) {
        if (v == par[v]) return v;
        return par[v] = find(par[v]);
    }

    bool merge(int a, int b) {
        a = find(a), b = find(b);
        if (a == b) return false;
        else {
            if (size[a] < size[b]) swap(a, b);
            par[b] = a;
            size[a] += size[b];
            return true;
        }
    }
};int n,m,k;
vvi v;
set<int> killed;
//i will return the 100 sar and more
int check(int mask) {
    vvi t = v;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++)if (mask&(i<<t[i][j]))t[i][j] = -100;
    }
    int mx = -1, mxi = -1;
    vi cnt(20);
    for (int i = 0; i < n; i++) {
        int num;
        for(num=0;num<m;num++){
            if(v[i][num]!=-100)break;
        }
        cnt[v[i][num]]++;
    }
    return max_element(all(cnt))-cnt.begin();
}
int ans=1e6;
void solve() {
    cin >> n >> m >> k;
    v.resize(n+5, vi(m+5));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++)cin >> v[i][j];
    }
    cout << check(0) << endl;
    for(int i=0;i<(1<<m);i++){
        int c=check(i);
        if(c==k)ans=min(ans,(int)popcnt(i));
    }
    cout << ans << endl;
}
signed mishari() {
    mustawa;
    //usaco("berries");
    int tescases = 1;
    //cin>>tescases;
    for (int i = 1; i <= tescases; i++) {
        //cout<<"Case "<<i<<":"<<endl;
        solve();
    }
}

Compilation message

izbori.cpp: In function 'long long int check(long long int)':
izbori.cpp:111:9: warning: unused variable 'mx' [-Wunused-variable]
  111 |     int mx = -1, mxi = -1;
      |         ^~
izbori.cpp:111:18: warning: unused variable 'mxi' [-Wunused-variable]
  111 |     int mx = -1, mxi = -1;
      |                  ^~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 9 ms 348 KB Partially correct
2 Partially correct 14 ms 344 KB Partially correct
3 Partially correct 4 ms 480 KB Partially correct
4 Partially correct 32 ms 348 KB Partially correct
5 Partially correct 7 ms 344 KB Partially correct
6 Partially correct 4 ms 348 KB Partially correct
7 Partially correct 1 ms 348 KB Partially correct
8 Partially correct 18 ms 456 KB Partially correct
9 Partially correct 20 ms 488 KB Partially correct
10 Partially correct 1 ms 348 KB Partially correct
11 Correct 17 ms 348 KB Output is correct
12 Partially correct 73 ms 344 KB Partially correct
13 Partially correct 150 ms 344 KB Partially correct
14 Partially correct 70 ms 468 KB Partially correct
15 Partially correct 23 ms 600 KB Partially correct
16 Partially correct 172 ms 480 KB Partially correct
17 Partially correct 80 ms 344 KB Partially correct
18 Partially correct 164 ms 344 KB Partially correct
19 Partially correct 180 ms 348 KB Partially correct
20 Partially correct 184 ms 344 KB Partially correct