답안 #501016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501016 2022-01-02T07:53:33 Z dostigator Gift (IZhO18_nicegift) C++17
컴파일 오류
0 ms 0 KB
// author lox:(
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define popcnt __builtin_popcount
#define all(a) a.begin(),a.end()
#define low_b lower_bound
#define up_b upper_bound
#define vii vector<pair<ll,ll>>
#define vll vector<pair<ll,ll>>
#define pii pair<ll,ll>
#define mii map<ll,ll>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define endl '\n'
#define Y second
#define X first
typedef long double ld;
typedef long long ll;
const ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},col=107,N=3e6+777;
const ll mod=1e9+7,inf=1e18;
void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
ll binpow(ll n,ll k){if(k<0)return 0ll;if(k==0)return 1ll;if(k%2)return (binpow(n,k-1)*n)%mod;ll kk=binpow(n,k/2)%mod;return (kk*kk)%mod;}
void solve(){
	int n;
	cin>>n;
	pii a[n+2];
	for(int i=1; i<=n; ++i){
        cin>>a[i].X;
        a[i].Y=i;
        sum+=a[i];
	}
	sort(a+1,a+1+n);
	if(sum%k) {cout<<"-1\n";return;}
	cout<<sum/2<<endl;
	for(int i=1; i<=sum/2; ++i){
		cout<<"1 "<<a[n].y<<' '<<a[n-1].y<<endl;
		a[n].x--;
		a[n-1].x--;
		sort(a+1,a+1+n);
	}
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //fre_open
    ll tt=1;
    //cin>>tt;
    while(tt--) solve();
}

Compilation message

nicegift.cpp: In function 'void solve()':
nicegift.cpp:35:9: error: 'sum' was not declared in this scope
   35 |         sum+=a[i];
      |         ^~~
nicegift.cpp:38:5: error: 'sum' was not declared in this scope
   38 |  if(sum%k) {cout<<"-1\n";return;}
      |     ^~~
nicegift.cpp:38:9: error: 'k' was not declared in this scope
   38 |  if(sum%k) {cout<<"-1\n";return;}
      |         ^
nicegift.cpp:39:8: error: 'sum' was not declared in this scope
   39 |  cout<<sum/2<<endl;
      |        ^~~
nicegift.cpp:41:20: error: 'struct std::pair<long long int, long long int>' has no member named 'y'
   41 |   cout<<"1 "<<a[n].y<<' '<<a[n-1].y<<endl;
      |                    ^
nicegift.cpp:41:35: error: 'struct std::pair<long long int, long long int>' has no member named 'y'
   41 |   cout<<"1 "<<a[n].y<<' '<<a[n-1].y<<endl;
      |                                   ^
nicegift.cpp:42:8: error: 'struct std::pair<long long int, long long int>' has no member named 'x'
   42 |   a[n].x--;
      |        ^
nicegift.cpp:43:10: error: 'struct std::pair<long long int, long long int>' has no member named 'x'
   43 |   a[n-1].x--;
      |          ^
nicegift.cpp: In function 'void fre_open()':
nicegift.cpp:26:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 | void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:26:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 | void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
      |                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~