Submission #1033830

# Submission time Handle Problem Language Result Execution time Memory
1033830 2024-07-25T06:47:15 Z shjeong Cave (IOI13_cave) C++17
0 / 100
115 ms 65536 KB
#include "cave.h"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
typedef long long ll;
using namespace std;
void exploreCave(int N) {
    int *s = (int*)malloc(N*sizeof(int));
    int *ans = (int*)malloc(N*sizeof(int));   //s[i] = j : i번 문은 j번 스위치 / ans[i] = j : i번 스위치는 j
    vector<bool> vis(N);
    for(int i = 0 ; i < N ; i++){
        int *tmp = (int*)malloc(N*sizeof(int));
        memset(tmp,0,sizeof(tmp));
        vector<ll> idx;
        for(int j = 0 ; j < N ; j++){
            if(!vis[j])idx.push_back(j);
        }
        for(int j = 0 ; j < i ; j++)tmp[s[j]] = ans[s[j]];
        ll x = tryCombination(tmp);
        bool f = (x==i);
        ll l = -1, r = (int)idx.size();
        while(l+1 < r){
            ll mid = l+r>>1;
            for(int i = l+1 ; i <= mid ; i++)tmp[idx[i]] = 0;
            for(int i = mid+1 ; i < r ; i++)tmp[idx[i]] = 1;
            ll x = tryCombination(tmp);
            if((x==i) == f){
                if(f==0)r = mid;
                else l = mid;
            }
            else{
                if(f==0)l = mid;
                else r = mid;
            }
        }
        ans[idx[r]] = f;
        s[i] = idx[r];
        vis[idx[r]] = 1;
    }
    answer(ans,s);
}

Compilation message

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:14:22: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
   14 |         memset(tmp,0,sizeof(tmp));
      |                      ^~~~~~~~~~~
cave.cpp:24:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |             ll mid = l+r>>1;
      |                      ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 115 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 436 KB Answer is wrong
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 436 KB Answer is wrong
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -