답안 #466075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466075 2021-08-17T20:36:06 Z nickmet2004 popa (BOI18_popa) C++11
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "popa.h"
using namespace std;
/*
int query(int a , int b , int l , int r){
    int k =s[a];
    for(int i = a+1; i<= b; ++i)k = __gcd(k , s[i]);
    int j = s[l];
    for(int i = l + 1; i <= r; ++i)j = __gcd(j , s[i]);
    return k == j;
}
*/
int solve(int n , int *Left , int *Right) {
	stack<int> st;
	int root = 0;
	memset(Left , -1 , sizeof(Left));
	memset(Right , -1 , sizeof(Right));
	st.push(0);
	for(int i  =1; i < n; ++i){
        while(st.size() && query(st.top() , i , i , i)){
            Right[st.top()] = left[i];
            Left[i] = st.top();
            st.pop();
        }
	}
	if(st.size()) Right[st.top()] = i;
	else root = i;
	return root;
}
/*
int main (){

    int n;
    cin >> n;
    for(int i = 0; i< n; ++i)cin >> s[i];
    memset(Left , -1 , sizeof(Left));memset(Right , -1 , sizeof(Right));
    cout << solve(n)<<endl;
    for(int i = 0; i < n; ++i)cout << Left[i] << " " << Right[i] << endl;

}
*/
///20 80 40
///40 80 20

Compilation message

popa.cpp: In function 'int solve(int, int*, int*)':
popa.cpp:16:21: 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]
   16 |  memset(Left , -1 , sizeof(Left));
      |                     ^~~~~~~~~~~~
popa.cpp:17: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]
   17 |  memset(Right , -1 , sizeof(Right));
      |                      ^~~~~~~~~~~~~
popa.cpp:21:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   21 |             Right[st.top()] = left[i];
      |                                     ^
popa.cpp:21:37: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   21 |             Right[st.top()] = left[i];
      |                               ~~~~~~^
      |                                     |
      |                                     std::ios_base& (*)(std::ios_base&)
popa.cpp:26:34: error: 'i' was not declared in this scope
   26 |  if(st.size()) Right[st.top()] = i;
      |                                  ^
popa.cpp:27:14: error: 'i' was not declared in this scope
   27 |  else root = i;
      |              ^