제출 #1264484

#제출 시각아이디문제언어결과실행 시간메모리
1264484YassirSalamaGift (IZhO18_nicegift)C++20
0 / 100
140 ms22736 KiB
#pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define endl "\n"
using ull=unsigned long long;
using pii=pair<int,int>;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
    copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int maxn = 1e5+100;
const int mod = 1e9+7;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    cin>>v;
    vector<int> c;
    __int128_t p = 1;
    __int128_t INF = (1LL<<60);
    for(int i = 0;i<n;i++){
        p*=v[i];
        if(p>INF){
            int l = 0;
            int r = n-1;
            while(v[l]==1){
                l++;
            }
            while(v[r]==1){
                r--;
            }
            cout<<l+1<<" "<<r+1<<endl;
            return;
        }
        if(v[i]>1){
            c.pb(i);
        }
    }
    if(c.size()>100){
            int l = 0;
            int r = n-1;
            while(v[l]==1){
                l++;
            }
            while(v[r]==1){
                r--;
            }
            cout<<l+1<<" "<<r+1<<endl;
            return;
    }
    __int128_t pref[n];
    __int128_t suff[n];
    for(int i = 0;i<n;i++){
        pref[i] = v[i];
        if(i) pref[i]+=pref[i-1];
    }
    for(int i = n-1;i>=0;i--){
        suff[i] = v[i];
        if(i+1<n){
            suff[i]+=suff[i+1];
        }
    }
    int l = 0;
    int r = 0;
    __int128_t best = 0;
    for(int i = 0;i<c.size();i++){
        __int128_t prod = 1;
        for(int j = i;j<c.size();j++){

            prod*=v[c[j]];
            __int128_t cost = (c[i]?pref[c[i]-1]:0)+(c[j]+1<n?suff[c[j]+1]:0)+prod;
            if(cost>best){
                l = c[i];
                r = c[j];
                best = cost;
            }
        }
    }
    cout<<l+1<<" "<<r+1<<endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    if(n%k!=0){
        cout<<-1<<endl;
        return 0;
    }vector<int> v(n);cin>>v;
    cout<<n/k<<endl;
    for(int i = 0;i<n;i+=k){
        cout<<v[0]<<" ";
        for(int j = i;j<i+k;j++){
            cout<<j+1<<" ";
        }
        cout<<endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...