Submission #1109239

# Submission time Handle Problem Language Result Execution time Memory
1109239 2024-11-06T08:42:27 Z cpptowin Kpart (eJOI21_kpart) C++17
100 / 100
737 ms 4692 KB
#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf (int)1e18
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1LL)
#define offbit(i,j) (i^(1LL<<j))
#define onbit(i,j) (i|(1LL<<j))
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define ss(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
template <typename T1, typename T2> bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int mod = 1e9 + 7;
const int nsqrt = 450;
int n,a[maxn],pos[maxn],p[maxn];
void solve()
{
    cin >> n;
    vi candidate;
    fo(i,1,n)
    {
        cin >> a[i],candidate.pb(i);
        p[i] = p[i - 1] + a[i];
    }
    fo(i,1,50000) pos[i] = -1;
    fo(i,1,n)
    {
        vi newcandidate;
        pos[0] = i;
        fod(j,50000,a[i]) maximize(pos[j],pos[j - a[i]]);
        for(int it : candidate)
        {
            if(it > i)
            {
                newcandidate.pb(it);
                continue;
            }
            int val = p[i] - p[i - it];
            if(val & 1) continue;
            if(pos[val / 2] > i - it) newcandidate.pb(it);
        }
        candidate = newcandidate;
    }
    cout << ss(candidate) << ' ';
    for(int it : candidate) cout << it << ' ';en;
}
main()
{
#define name "TASK"
    if(fopen(name".inp","r"))
    {
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin >> T;
    while(T--) solve();
}

Compilation message

Main.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 4448 KB Output is correct
2 Correct 84 ms 4584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 4432 KB Output is correct
2 Correct 316 ms 4684 KB Output is correct
3 Correct 296 ms 4432 KB Output is correct
4 Correct 448 ms 4616 KB Output is correct
5 Correct 589 ms 4680 KB Output is correct
6 Correct 737 ms 4692 KB Output is correct
7 Correct 725 ms 4676 KB Output is correct