답안 #223732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223732 2020-04-16T09:03:20 Z bharat2002 Detecting Molecules (IOI16_molecules) C++14
0 / 100
5 ms 384 KB
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
const int N=2e5 + 100;
const int mod=1e9 + 7;
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
int n;vector< pii > vals;
bool sf(pii a, pii b);int pref[N];
vector<int> ans;int L, U;
void check(int num)
{
	if(pref[num-1]<=U)
	{
		for(int i=0;i<num;i++) ans.push_back(vals[i].s);return;
	}
	for(int i=num;i<n;i++)
	{
		if(pref[i]-pref[i-num]>=L&&pref[i]-pref[i-num]<=U)
		{
			for(int j=i-num+1;j<=i;j++) ans.push_back(vals[j].s);return;
		}
	}
}
vector<int> find_subset(int l, int u, vector<int> w)
{
	vals.clear();L=l;U=u;
	n=w.size();
	for(int i=0;i<w.size();i++)
	{
		vals.push_back(mp(w[i], i));
	}
	sort(vals.begin(), vals.end(), sf);
	int mval=vals.back().f;
	for(auto &i:vals) i.f-=mval;
		pref[0]=0;;
	for(int i=0;i<vals.size();i++)
	{
		pref[i]=vals[i].f;
		if(i>0) pref[i]+=pref[i-1];
	}

	if(mval>u) return ans;
	for(int i=1;i<=n;i++)
	{
		if(i==n)
		{
			if(pref[n-1]>=l&&pref[n-1]<=u)
			{
				for(int i=0;i<n;i++) ans.push_back(vals[i].s);
			}
			break;
		}
		int maxsum=pref[i-1], minsum=pref[n-1] - pref[n-i-1];
		if(minsum<=l&&maxsum>=l)
		{
			check(i);
			if(!ans.empty()) break;
		}
	}
	return ans;
}
bool sf(pii a, pii b)
{
	return a.f>b.f;
}

Compilation message

molecules.cpp: In function 'void check(int)':
molecules.cpp:17:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for(int i=0;i<num;i++) ans.push_back(vals[i].s);return;
   ^~~
molecules.cpp:17:51: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   for(int i=0;i<num;i++) ans.push_back(vals[i].s);return;
                                                   ^~~~~~
molecules.cpp:23:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for(int j=i-num+1;j<=i;j++) ans.push_back(vals[j].s);return;
    ^~~
molecules.cpp:23:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for(int j=i-num+1;j<=i;j++) ans.push_back(vals[j].s);return;
                                                         ^~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:31:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<w.size();i++)
              ~^~~~~~~~~
molecules.cpp:39:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vals.size();i++)
              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 384 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB Contestant can not find answer, jury can
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 384 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 384 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 384 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 384 KB Contestant can not find answer, jury can
4 Halted 0 ms 0 KB -