답안 #1024446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024446 2024-07-16T05:20:31 Z Otalp 드문 곤충 (IOI22_insects) C++17
0 / 100
1 ms 344 KB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back


void put(int x){
    move_inside(x - 1);
}

void pop(int x){
    move_outside(x - 1);
}

int get(){
    return press_button();
}

int min_cardinality(int N) {
    int n = N;
    vector<int> d;
    map<int, int> q, cnt;
    int ls = 0;
    for(int i=1; i<=n; i++){
        put(i);
        if(get() == 1){
            q[i] = ++ls;
            cnt[ls] = 1;
            d.pb(i);
            continue;
        }
        for(int x: d){
            pop(x);
            if(get() == 1){
                cnt[q[x]] ++;
                q[i] = q[x];
                put(x);
                break;
            }
        }
        pop(i);
    }
    int ans = -1, mn = 1e9;
    for(int i=1; i<=n; i++){
        cout<<i<<' '<<q[i]<<'\n';
        if(cnt[q[i]] < mn){
            ans = i;
            mn = cnt[q[i]];
        }
    }
    cout<<1/0;
    return ans-1;
        
                
        
        
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:51:12: warning: division by zero [-Wdiv-by-zero]
   51 |     cout<<1/0;
      |           ~^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -