Submission #973450

# Submission time Handle Problem Language Result Execution time Memory
973450 2024-05-02T02:38:30 Z modwwe Kas (COCI17_kas) C++17
100 / 100
248 ms 196244 KB
#include<bits/stdc++.h>
//#define int long long
#define d0 1
#define d1 11
#define d2 110
#define d3 1010
#define d4 10010
#define d5 100010
#define d6 1000010
#define down cout<<'\n';
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define debug(x) cerr<<x<<" ";
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "PALIVAL"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define sz(s) s.size()
#define pii pair<int,int>
#define pb push_back
#define checktime   cout << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define reb(i,m,n) for(int i=m;i>=n;i--)
#define ALL(v) v.begin(), v.end()
#define base 31
#define base2 37
using namespace std;
void phongbeo();
void de();
template<typename A, typename B>istream& operator>>(istream& in, pair<A, B> &v)
{
    in >> v.first >> v.second;
    return in;
}
template<typename A, typename B> ostream& operator<<(ostream& out, const pair<A, B> &v)
{
    out << v.first << " " << v.second << " ";
    return out;
}
template < class T > bool minimize(T& a, const T& b)
{
    return b < a ? a = b, 1 : 0;
}
template < class T > bool maximize(T& a, const T& b)
{
    return a < b ? a = b, 1 : 0;
}
mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count    ());
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy2[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//const int mod2=1e9+7;
//const int mod=1073741824;
//const int  mod1=998244353;
struct ib
{
    int a;
    int b;
};
struct icd
{
    int a,b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
//int minn=1e9,maxx=-1e9;
int n,m,s2,s4,s3,sf,k,l,r,dem=0,l1,r1,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0;
int  s,i;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
//fin(task),fou(task);
//#endif
    NHP
//modwwe
    phongbeo(),down
#ifndef ONLINE_JUDGE
//checktime
#endif
}
int dp[501][100001];
int a[501];
void phongbeo()
{
 cin>>n;
  for(int i=1;i<=n;i++)
    {
        cin>>a[i];
     dem+=a[i];
    }
     dp[1][a[1]]=a[1];
    for(int i=2;i<=n;i++)
    for(int j=0;j<=dem;j++)
    {
        dp[i][j]=dp[i-1][j];
        dp[i][a[i]]=max({dp[i][a[i]],dp[i-1][a[i]],a[i]});
   if(dp[i-1][j+a[i]]!=0)dp[i][j]=max(dp[i][j],dp[i-1][j+a[i]]+a[i]);
   if(dp[i-1][abs(j-a[i])]!=0)dp[i][j]=max(dp[i][j],dp[i-1][abs(j-a[i])]+a[i]);
    }
    cout<<dem-dp[n][0]+dp[n][0]/2;
  }

Compilation message

kas.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 16848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 3 ms 20952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 78748 KB Output is correct
2 Correct 122 ms 98344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 117980 KB Output is correct
2 Correct 197 ms 157156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 176724 KB Output is correct
2 Correct 248 ms 196244 KB Output is correct