제출 #855399

#제출 시각아이디문제언어결과실행 시간메모리
855399vjudge1수열 (APIO14_sequence)C++17
0 / 100
1 ms600 KiB
/// tree bends in youth /// 1.10.2023 /// success is doing same thing in every single day!!! #include <bits/stdc++.h> #define ll long long #define pb push_back #define all(x) x.begin(), x.end() #define F first #define S second using namespace std; const ll N =2e5 + 5; const ll NN = 2e5; const ll INF = 1e9; const ll MOD = 1e9 + 7; int a[15]; int n,k,ans; bool used[15]; int b[15]; int p[15]; void per(int i){ if(i == k + 1){ ll res = 0; //// мы должны найти res set <pair<int,int>> s; s.insert({1,n}); for(int i = 1;i <= k;i++){ int l = 0,r = 0; for(pair<int,int> to : s){ if(to.F <= p[i] && to.S >= p[i]){ l = to.F,r = to.S; break; } } ll left = 0,right = 0; for(int j = l;j <= p[i];j++){ left += a[j]; } for(int j = p[i]+ 1;j <= r;j++){ right += a[j]; } res += (right * left); s.erase({l,r}); s.insert({l,p[i]}); s.insert({p[i] + 1,r}); } if(res > ans){ ans= res; for(int i = 1;i <= k;i++){ b[i] = p[i]; } } } else{ for(int j = 1;j <= n;j++){ if(used[j] == 0){ used[j] = 1; p[i] = j; per(i + 1); used[j] = 0; } } } } void solve(){ cin >> n >> k; for(int i= 1;i <= n;i++){ cin >> a[i]; } per(1); cout << ans << '\n'; for(int i = 1;i <= k;i++){ cout << b[i] << ' '; } } main (){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("moocrypt.in","r",stdin); // freopen("moocrypt.out","w",stdout); ll abd= 1; // cin >> abd; for(ll i = 1;i <= abd;i++){ // cout << "Case " << i << ": "; solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main (){
      | ^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...