제출 #812301

#제출 시각아이디문제언어결과실행 시간메모리
812301mindiyak수열 (APIO14_sequence)C++14
0 / 100
6 ms3104 KiB
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (ll i = a; i < (b); i++) #define F0R(i, a) for (ll i = 0; i < (a); i++) #define FORd(i, a, b) for (ll i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (ll i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define fst first #define nl endl #define sec second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; const int MX = INT_MAX; const int MN = INT_MIN; void init() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); } ll get_sum(vpi arr){ ll sum=0;trav(a,arr)sum+=a.first;return sum; } pair<pair<int,int>,ll> get_mid(vpi arr,ll sum){ ll temp=0;FOR(i,0,arr.size()){temp+=arr[i].first;if(temp>=(sum/2))return {{i,arr[i].second},temp};} return {{arr.size()-1,arr[arr.size()-1].second},temp}; } ll ans = 0; vi ansdata; vector<pair<ll,vpi>> split(vpi arr){ vector<pair<ll,vpi>> split_arr; if(arr.size()==2){ ans += arr[0].first * arr[1].first; ansdata.pb(arr[0].second); return split_arr; } int sum = get_sum(arr); pair<pair<int,int>,ll> mid = get_mid(arr,sum); ans += (mid.second) * (sum-mid.second); ansdata.pb(mid.first.second); vpi temp_a = {arr.begin(),arr.begin()+mid.first.first+1}; int sum1 = get_sum(temp_a); pair<pair<int,int>,ll> mid1 = get_mid(temp_a,sum1); split_arr.pb({mid1.second,temp_a}); // cout<<"split 1 - " << mid1.second << endl;trav(j,temp_a){cout << "{" << j.first << "," << j.second << "} ";}cout << endl; temp_a = {arr.begin()+mid.first.first+1,arr.end()}; sum1 = get_sum(temp_a); mid1 = get_mid(temp_a,sum1); split_arr.pb({mid1.second,temp_a}); // cout<<"split 2 - " << (mid1.second) << endl;trav(j,temp_a){cout << "{" << j.first << "," << j.second << "} ";}cout << endl; return split_arr; } void solve() { int n,k;cin>>n>>k; vpi intarr; FOR(i,0,n){int a;cin >> a;if(a==0){continue;}intarr.pb({a,i});} priority_queue<pair<ll,vpi>> pq; int sum = get_sum(intarr); pair<pair<int,int>,ll> mid = get_mid(intarr,sum); pq.push({mid.second,intarr}); FOR(i,0,k){ pair<ll,vpi> topvar = pq.top();pq.pop(); // cout<<"start " << endl;trav(j,topvar.second){cout << "{" << j.first << "," << j.second << "} ";}cout << endl; if(topvar.second.size() <= 1){ k++; }else{ vector<pair<ll,vpi>> temp = split(topvar.second); FOR(j,0,temp.size())pq.push(temp[j]); } // cout << endl; } cout << ans << endl; trav(a,ansdata)cout << a+1 << " "; } int main() { fastIO(); // init(); int t = 1; // cin >> t; while (t--) solve(); return 0; }

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

sequence.cpp: In function 'std::pair<std::pair<int, int>, long long int> get_mid(vpi, ll)':
sequence.cpp:17:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 | #define FOR(i, a, b) for (ll i = a; i < (b); i++)
      |                                       ^
sequence.cpp:55:15: note: in expansion of macro 'FOR'
   55 |     ll temp=0;FOR(i,0,arr.size()){temp+=arr[i].first;if(temp>=(sum/2))return {{i,arr[i].second},temp};}
      |               ^~~
sequence.cpp: In function 'void solve()':
sequence.cpp:17:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::vector<std::pair<int, int> > > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 | #define FOR(i, a, b) for (ll i = a; i < (b); i++)
      |                                       ^
sequence.cpp:114:13: note: in expansion of macro 'FOR'
  114 |             FOR(j,0,temp.size())pq.push(temp[j]);
      |             ^~~
sequence.cpp: In function 'void init()':
sequence.cpp:40:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...