This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) (((xxxx)>>(aaaa-1))&1)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<pair<int,int>,pair<int,int>> piiii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;
typedef pair<long double,long double> pld;
typedef pair<pair<long double,long double>,long double> plld;
typedef pair<long double,long long> pdl;
const ll base=361;
const ll mod=1e9;
const ll mod2=1e9;
const ld eps=1e-3;
const ld eps2=1e-7;
const ll maxn=2e5+9;
const ll maxsize=6e5+29;
const ld pi=acos(-1);
//const ll delta=1e5+7;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
const int dxkn[8]={1,1,2,2,-1,-1,-2,-2};
const int dykn[8]={2,-2,1,-1,2,-2,1,-1};
const int dxki[8]={1,1,1,0,0,-1,-1,-1};
const int dyki[8]={1,0,-1,1,-1,1,0,-1};
vector<int> solvesub1(int l,int u,vector<pii> w) {
vector<int> kq;
kq.clear();
int sum=0;
for (int i=0;i<w.size();i++) {
sum+=w[i].fi;
kq.push_back(w[i].se);
if (l<=sum&&sum<=u) {
return kq;
}
if (sum>u) {
return {};
}
}
return {};
}
vector<int> solvesub2(int l,int u,vector<pii> w) {
vector<int> kq;
kq.clear();
int sum=0;
int rsum=0;
int cnt=0;
int len=0;
for (int i=0;i<w.size();i++) {
if (w[i].fi!=w[0].fi) {
cnt++;
}
}
for (int i=0;i<w.size();i++) {
sum+=w[0].fi;
len++;
rsum=min(sum+len,sum+cnt);
int p1,p2;
p1=max(l,sum);
p2=min(u,rsum);
if (p1<=p2) {
int k1=p1-sum;
int k2=len-k1;
//cout<<sum<<' '<<rsum<<' '<<k1<<' '<<k2<<'\n';
for (int j=0;j<w.size();j++) {
if (w[j].fi==w[0].fi&&k2>0) {
k2--;
kq.push_back(w[j].se);
}
else if (w[j].fi==w.back().fi&&k1>0) {
k1--;
kq.push_back(w[j].se);
}
}
return kq;
}
if (sum>u) {
return {};
}
}
return {};
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<int> kq;
kq.clear();
vector<pii> new_w;
new_w.clear();
for (int i=0;i<w.size();i++) {
new_w.push_back({w[i],i});
}
sort(new_w.begin(),new_w.end());
if (new_w[0].fi==new_w.back().fi) {
return solvesub1(l,u,new_w);
}
else if (new_w.back().fi-new_w[0].fi==1) {
return solvesub2(l,u,new_w);
}
return kq;
}
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> solvesub1(int, int, std::vector<std::pair<int, int> >)':
molecules.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i=0;i<w.size();i++) {
| ~^~~~~~~~~
molecules.cpp: In function 'std::vector<int> solvesub2(int, int, std::vector<std::pair<int, int> >)':
molecules.cpp:69:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int i=0;i<w.size();i++) {
| ~^~~~~~~~~
molecules.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (int i=0;i<w.size();i++) {
| ~^~~~~~~~~
molecules.cpp:85:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int j=0;j<w.size();j++) {
| ~^~~~~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:109:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int i=0;i<w.size();i++) {
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |