답안 #879645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879645 2023-11-27T19:23:47 Z mychecksedad Let's Win the Election (JOI22_ho_t3) C++17
컴파일 오류
0 ms 0 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e3+100, M = 1e5+10, K = 52, MX = 30;


int n, k, sum[N][N];
array<int, 2> a[N];
pair<int, double> dp[N][N];

double get(int x, double y, double j){
  return y + x/j; 
}

void solve(){
  cin >> n >> k;
  for(int i = 1; i <= n; ++i){
    cin >> a[i][1] >> a[i][0];
    if(a[i][0] == -1) a[i][0] = MOD;
  }
  sort(a+1, a+1+n);

  for(int j = 0; j <= n; ++j) dp[n+1][j] = 0;
  for(int i = n; i >= 1; --i){
    for(int j = 0; j < n - i + 1; ++j){
      sum[i][j] = min(sum[i + 1][j], j == 0 ? MOD : sum[i + 1][j - 1] + a[i][1]);
    }
    sum[i][n - i + 1] = sum[i + 1][n - i] + a[i][1];
  }
  double ans = sum[1][k];

  for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) dp[i][j] = {MOD, MOD};
  dp[0][0] = {0, 0};
  for(int i = 1; i <= k; ++i){
    dp[i][0] = dp[i - 1][0];
    dp[i][0].first += a[i][1];
    for(int j = 1; j <= i; ++j){
      double val1 = get(dp[i - 1][j].first + a[i][1], dp[i - 1][j].second, j + 1);
      double val2 = get(dp[i - 1][j - 1].first, dp[i - 1][j - 1].second + a[i][0] / (double) j, j + 1);
      if(val1 <= val2){
        dp[i][j] = {dp[i - 1][j].first + a[i][1], dp[i - 1][j].second};
      }else{
        dp[i][j] = {dp[i - 1][j - 1].first, dp[i - 1][j - 1].second + a[i][0] / (double) j};
      }
      ans = min(ans, get(sum[i + 1][k - i] + dp[i][j].first, dp[i][j].second, j + 1));
    }
  }
  cout << fixed << setprecision(5);
  cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:29:44: error: no match for 'operator=' (operand types are 'std::pair<int, double>' and 'int')
   29 |   for(int j = 0; j <= n; ++j) dp[n+1][j] = 0;
      |                                            ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:2:
/usr/include/c++/10/bits/stl_pair.h:390:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type) [with _T1 = int; _T2 = double; typename std::conditional<std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const std::__nonesuch&>::type = const std::pair<int, double>&]'
  390 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:393:41: note:   no known conversion for argument 1 from 'int' to 'std::conditional<true, const std::pair<int, double>&, const std::__nonesuch&>::type' {aka 'const std::pair<int, double>&'}
  390 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~    
  391 |   __and_<is_copy_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
  392 |          is_copy_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  393 |   const pair&, const __nonesuch&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:401:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type) [with _T1 = int; _T2 = double; typename std::conditional<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>::type = std::pair<int, double>&&]'
  401 |       operator=(typename conditional<
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:404:31: note:   no known conversion for argument 1 from 'int' to 'std::conditional<true, std::pair<int, double>&&, std::__nonesuch&&>::type' {aka 'std::pair<int, double>&&'}
  401 |       operator=(typename conditional<
      |                 ~~~~~~~~~~~~~~~~~~~~~
  402 |   __and_<is_move_assignable<_T1>,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  403 |          is_move_assignable<_T2>>::value,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404 |   pair&&, __nonesuch&&>::type __p)
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = double]'
  418 |  operator=(const pair<_U1, _U2>& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:418:2: note:   template argument deduction/substitution failed:
Main.cpp:29:44: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   29 |   for(int j = 0; j <= n; ++j) dp[n+1][j] = 0;
      |                                            ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:2:
/usr/include/c++/10/bits/stl_pair.h:430:2: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = double]'
  430 |  operator=(pair<_U1, _U2>&& __p)
      |  ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:430:2: note:   template argument deduction/substitution failed:
Main.cpp:29:44: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   29 |   for(int j = 0; j <= n; ++j) dp[n+1][j] = 0;
      |                                            ^
Main.cpp: In function 'int main()':
Main.cpp:61:15: warning: unused variable 'aa' [-Wunused-variable]
   61 |   int tt = 1, aa;
      |               ^~