답안 #73329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73329 2018-08-28T07:26:59 Z 노영훈(#2269) Happiness (Balkan15_HAPPINESS) C++11
30 / 100
2000 ms 2212 KB
#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll linf=2e18;

int n;
ll C[200010];

bool check(){
	ll sum=1;
	for(int i=1; i<=n; i++){
		if(C[i]>sum) return false;
		sum+=C[i];
	}
	return true;
}

bool init(int N, ll maxCoinSize, ll coins[]) {
	n=N;
	for(int i=0; i<n; i++) C[i+1]=coins[i];
	sort(C+1, C+n+1);
	return check();
}
bool is_happy(int event, int k, ll coins[]) {
	vector<ll> D;
	for(int i=0; i<k; i++) D.push_back(coins[i]);
	
	if(event<0){
		for(int i=1, j=0; i<=n; i++){
			C[i-j]=C[i];
			auto it=find(D.begin(), D.end(), C[i]);
			if(it!=D.end()) j++, *it=linf;
		}
		n-=k;
	}
	else{
		for(int i=n+1; i<=n+k; i++) C[i]=-1; n+=k;
		for(int i=1; i<=n; i++){
			int p=min_element(D.begin(), D.end())-D.begin();
			if(C[i]<0) C[i]=D[p], D[p]=linf;
			else if(C[i]>D[p]) swap(D[p], C[i]);
		}
	}
	
	return check();
}

Compilation message

happiness.cpp: In function 'bool is_happy(int, int, ll*)':
happiness.cpp:38:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for(int i=n+1; i<=n+k; i++) C[i]=-1; n+=k;
   ^~~
happiness.cpp:38:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   for(int i=n+1; i<=n+k; i++) C[i]=-1; n+=k;
                                        ^
grader.cpp: In function 'int main()':
grader.cpp:14:9: warning: unused variable 'd' [-Wunused-variable]
  int i, d;
         ^
grader.cpp:15:12: warning: unused variable 'max_code' [-Wunused-variable]
  long long max_code;
            ^~~~~~~~
grader.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~~
grader.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &coins[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~
grader.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
grader.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &ck, &c);
   ~~~~~^~~~~~~~~~~~~~~~~
grader.cpp:28:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", &A[j]);
    ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 488 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 55 ms 676 KB Output is correct
4 Correct 60 ms 708 KB Output is correct
5 Correct 53 ms 708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2078 ms 2120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2056 ms 2212 KB Time limit exceeded
2 Halted 0 ms 0 KB -