답안 #630833

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630833 2022-08-17T07:31:04 Z TimDee 메기 농장 (IOI22_fish) C++17
18 / 100
90 ms 9300 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


ll p2(int n, int m, vector<int> x, vector<int> y, vector<int> w) {

  vector<int> a(n,0), b(n,0);
  ll sum=0;
  for (int i=0; i<m; ++i) {
    if (x[i]==0) a[y[i]]=w[i];
    else b[y[i]]=w[i];
    sum+=w[i];
  }
  ll ans=0;
  for (int i=0; i<n; ++i) ans+=b[i];
  if (n==2) return max(ans,sum-ans);
  ll cnt=ans;
  for (int i=0; i<n; ++i) {
    cnt+=1ll*a[i]-1ll*b[i];
    ans=max(ans,cnt);
  }
  return ans;

}

ll p3(int n, int m, vector<int> x, vector<int> w) {

  vector<int> a(n,0);
  for (int i=0; i<m; ++i) a[x[i]]=w[i];
  vector<vector<ll>> dp(n+1,vector<ll>(2,0));
  dp[1]={a[1],0};
  //cout<<"#0 0 0\n#1 "<<dp[1][0]<<' '<<dp[1][1]<<'\n';
  for (int i=2; i<=n; ++i) {
    dp[i][0]=max({dp[i-2][1]+((i<n)?a[i]:0)+a[i-2],dp[i-2][0]+((i<n)?a[i]:0),dp[i-1][0]-a[i-1]+((i<n)?a[i]:0)});
    dp[i][1]=max(dp[i-1][0],dp[i-1][1]);
    //cout<<"#"<<i<<' '<<dp[i][0]<<' '<<dp[i][1]<<'\n';
  }

  return max(dp[n][0],dp[n][1]);

}

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {

  int _p1=1, _p2=1, _p3=1;
  ll sum=0;
  for (int i=0; i<m; ++i) {
    _p1&=!(x[i]&1);
    _p2&=(x[i]<=1);
    _p3&=(y[i]==0);
    sum+=w[i];
  }

  if (_p1) return sum;
  if (_p2) return p2(n,m,x,y,w);
  if (_p3) return p3(n,m,x,w);

}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2068 KB Output is correct
2 Correct 26 ms 2632 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 83 ms 7276 KB Output is correct
6 Correct 90 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 47 ms 6692 KB Output is correct
3 Correct 56 ms 8024 KB Output is correct
4 Correct 21 ms 2156 KB Output is correct
5 Correct 26 ms 2624 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 30 ms 3804 KB Output is correct
13 Correct 30 ms 4544 KB Output is correct
14 Correct 22 ms 3828 KB Output is correct
15 Correct 27 ms 4180 KB Output is correct
16 Correct 23 ms 3824 KB Output is correct
17 Correct 26 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 7 ms 6100 KB Output is correct
3 Correct 20 ms 7216 KB Output is correct
4 Correct 16 ms 7328 KB Output is correct
5 Correct 33 ms 9284 KB Output is correct
6 Correct 29 ms 9292 KB Output is correct
7 Correct 32 ms 9292 KB Output is correct
8 Correct 30 ms 9264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 7 ms 6100 KB Output is correct
3 Correct 20 ms 7216 KB Output is correct
4 Correct 16 ms 7328 KB Output is correct
5 Correct 33 ms 9284 KB Output is correct
6 Correct 29 ms 9292 KB Output is correct
7 Correct 32 ms 9292 KB Output is correct
8 Correct 30 ms 9264 KB Output is correct
9 Incorrect 29 ms 9300 KB 1st lines differ - on the 1st token, expected: '99999', found: '66666'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2068 KB Output is correct
2 Correct 26 ms 2632 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 83 ms 7276 KB Output is correct
6 Correct 90 ms 7372 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 47 ms 6692 KB Output is correct
9 Correct 56 ms 8024 KB Output is correct
10 Correct 21 ms 2156 KB Output is correct
11 Correct 26 ms 2624 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 30 ms 3804 KB Output is correct
19 Correct 30 ms 4544 KB Output is correct
20 Correct 22 ms 3828 KB Output is correct
21 Correct 27 ms 4180 KB Output is correct
22 Correct 23 ms 3824 KB Output is correct
23 Correct 26 ms 4180 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 7 ms 6100 KB Output is correct
26 Correct 20 ms 7216 KB Output is correct
27 Correct 16 ms 7328 KB Output is correct
28 Correct 33 ms 9284 KB Output is correct
29 Correct 29 ms 9292 KB Output is correct
30 Correct 32 ms 9292 KB Output is correct
31 Correct 30 ms 9264 KB Output is correct
32 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
33 Halted 0 ms 0 KB -