답안 #30546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30546 2017-07-24T14:34:20 Z kavun 선물상자 (IOI15_boxes) C++14
컴파일 오류
0 ms 0 KB
#include "boxes.h"
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
long long n,l,k,ans = 1e18, cw[10000010], ccw[10000010], lmid = -1, rmid = -1;


long long delivery(int N, int K, int L, int p[]) {
  n = N;
  k = K;
  for(int i = 0; i < n; i++)
    {
      if(p[i] <= L/2)
	lmid = i;
      if(p[i] > L/2)
	{
	  rmid = i;
	  break;
	}
    }
  for(int i = 0; i < k; i++)
    cw[i] = 2*p[i];
  for(int i = k; i < n; i++)
    cw[i] = cw[i-k] + 2*p[i];
  for(int i = n-1; i >= n-k; i--)
    ccw[i] = 2*(L-p[i]);
  for(int i = n-k-1; i >= 0; i--)
    ccw[i] = ccw[i+k] + 2*(L-p[i]);
  for(int i = 0; i < n; i++)
    {
      if(i + k >= n-1)
	ans = min(ans,cw[i] + L);
      else if(p[i+k] > L/2)
	ans = min(ans,cw[i] + L + 2*ccw[i+k+1]);
    }
  long long ans2 = 0;
  if(lmid > -1)
    ans2 += cw[lmid];
  if(rmid > -1)
    ans2 += ccw[rmid];
  ans = min(ans,ans2);
  if(n == K && lmid > -1 && rmid > -1)
    ans = min(ans,L);

  return ans;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:24:15: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   for(int i = k; i < n; i++)
               ^
boxes.cpp:26:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   for(int i = n-1; i >= n-k; i--)
               ~^~
boxes.cpp:28:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   for(int i = n-k-1; i >= 0; i--)
               ~~~^~
boxes.cpp:44:20: error: no matching function for call to 'min(long long int&, int&)'
     ans = min(ans,L);
                    ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from boxes.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
boxes.cpp:44:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     ans = min(ans,L);
                    ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from boxes.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
boxes.cpp:44:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     ans = min(ans,L);
                    ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from boxes.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
boxes.cpp:44:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     ans = min(ans,L);
                    ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from boxes.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
boxes.cpp:44:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     ans = min(ans,L);
                    ^