제출 #58074

#제출 시각아이디문제언어결과실행 시간메모리
58074qkxwsm팀들 (IOI15_teams)C++17
0 / 100
4049 ms19380 KiB
#include "teams.h"
#include <bits/stdc++.h>

using namespace std;

template<class T>
void readi(T &x)
{
	T input = 0;
	bool negative = false;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = input * 10 + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	x = input;
}
template<class T>
void printi(T output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long randomize(long long mod)
{
	return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-20;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 500013

long long normalize(long long x, long long mod = INF)
{
	return (((x % mod) + mod) % mod);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M;
pii want[MAXN];
int arr[MAXN];
int ok[MAXN];
vector<pii> quer;
int tree[MAXN];

int get(int idx)
{
    int sum = 0ll;
    for (int e = idx; e > 0; e -= (e & (-e)))
    {
        sum += tree[e];
    }
    return sum;
}
void update(int idx, ll val)
{
    for (int e = idx; e <= N; e += (e & (-e)))
    {
        tree[e] += val;
    }
    return;
}

void init(int n, int A[], int B[])
{
	N = n;
	for (int i = 0; i < N; i++)
	{
		want[i] = MP(A[i], B[i]);
	}
	sort(want, want + N);
}

int can(int m, int k[])
{
	M = m;
	for (int i = 0; i < M; i++)
	{
		arr[i] = k[i];
	}
	sort(arr, arr + M);
	int s = 0;
	for (int i = 0; i < M; i++)
	{
		s += arr[i];
	}
	if (s > N)
	{
		return 0;
	}
	quer.clear();
	for (int i = 0; i < M; i++)
	{
		if (i == 0 || arr[i] != arr[i - 1])
		{
			quer.PB(MP(arr[i], 1));
		}
		else
		{
			quer.back().se++;
		}
	}
	//	cerr << "resolve\n";
	M = quer.size();
//	for (int i = 0; i < (1 << M); i++)
//	{
//		//		cerr << "go\n";
//		for (int j = 0; j <= N; j++)
//		{
//			ok[j] = 0;
//		}
//		int need = 0, have = 0;
//		for (int j = 0; j < M; j++)
//		{
//			if (!(i & (1 << j)))
//			{
//				continue;
//			}
//			need += quer[j].fi * quer[j].se;
//			ok[quer[j].fi] = 1;
//			//			cerr << "ok " << quer[j].fi << endl;
//		}
//		for (int j = 1; j <= N; j++)
//		{
//			ok[j] += ok[j - 1];
//		}
//		for (int j = 0; j < N; j++)
//		{
//			if (ok[want[j].se] - ok[want[j].fi - 1])
//			{
//				have++;
//			}
//		}
//		//		cerr << need << ' ' << have << endl;
//		if (have < need)
//		{
//			return 0;
//		}
//	}
	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j <= N; j++)
		{
			tree[j] = 0;
		}
		int need = 0;
		for (int j = i; j < M; j++)
		{
			need += quer[j].fi * quer[j].se;
			update(quer[j].fi, 1);
//			ok[quer[j].fi] = 1;
			int have = 0;
			for (int j = 0; j < N; j++)
			{
				if (get(want[j].se) - get(want[j].fi - 1))
				{
					have++;
				}
			}
			if (have < need)
			{
				return 0;
			}
		}
	}
	//	for (pii x : quer)
	//	{
	//		cerr << x.fi << ' ' << x.se << endl;
	//	}
	//for this subset, if the # of distinct people that can enter at least one of them is less than its sum, its bad
	//there are at most sqrtN distinct guys
	return 1;
	//check if the sum of values in subset of arr's is < sum cnt's of those arr's
	//you need to make a team if
}

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

teams.cpp: In function 'void update(int, ll)':
teams.cpp:125:17: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
         tree[e] += val;
         ~~~~~~~~^~~~~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:170:15: warning: conversion to 'int' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  M = quer.size();
      ~~~~~~~~~^~
teams.cpp:219:13: warning: declaration of 'j' shadows a previous local [-Wshadow]
    for (int j = 0; j < N; j++)
             ^
teams.cpp:213:12: note: shadowed declaration is here
   for (int j = i; j < M; j++)
            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...