QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629200#8005. Crossing the Borderpbk5418Compile Error//C++142.0kb2024-10-11 08:46:592024-10-11 08:47:00

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 08:47:00]
  • 评测
  • [2024-10-11 08:46:59]
  • 提交

answer

#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 22,P = 998244353,inf =  2e9;
int n,nn,W,R,S,T,mx[1 << N | 5],wt[1 << N | 5],f[1 << N | 5],g[1 << N | 5];
struct sib {int w,c;} e[31];
struct Node {int w,c,id;} ;
vector <Node> a;
vector <int> b[1 << 11 | 5];
inline int add(int x){return x >= P ? x - P : x;}
int main() {
	scanf("%d%d",&n,&W);
	for (int i = 0; i < n; i ++) scanf("%d%d",&e[i].w,&e[i].c);
	sort(e,e + n,[](sib x,sib y){return x.c > y.c;});
	nn = n / 2;
	S = 1 << n,T = 1 << nn,R = (1 << n - nn);
	for (int s = 0; s < S; s ++) f[s] = inf;
	for (int s = 1; s < S; s ++) {
		int i = s & -s,j = __lg(i);
		mx[s] = max(e[j].c,mx[s ^ i]);
		wt[s] = wt[s ^ i] + e[j].w;
	}
	f[0] = 0,g[0] = 1;
	for (int x = 0; x < R; x ++) {
		for (int X = x; X < R; X = (X + 1) | x) {
			if (X - x > x && wt[(X - x) << nn] <= W) {
				int fs = f[x << nn] + mx[(X - x) << nn];
				if (fs < f[X << nn]) f[X << nn] = fs,g[X << nn] = g[x << nn];
				else if (fs == f[X << nn]) g[X << nn] = add(g[X << nn] + g[x << nn]);
			}
			b[x].push_back(X);
		}
		sort(b[x].begin(),b[x].end(),[x](int A,int B){return wt[(A - x) << nn] > wt[(B - x) << nn];});
	}
	for (int Y = 1; Y < T; Y ++) {
		a.clear();
		for (int y = Y; y > 0; y = Y & (y - 1))
			if (Y - y > y) a.push_back(Node{wt[Y - y],mx[Y - y],y});
		a.push_back(Node{wt[Y],mx[Y],0});
		sort(a.begin(),a.end(),[](Node x,Node y){return x.w < y.w;});
		for (int x = 0; x < R; x ++) {
			int j = 0,F = inf,G = 0;
			for (int X : b[x]) {
				int ss = W - wt[(X - x) << nn],to = (X << nn) + Y;
				while (j < a.size() && a[j].w <= ss) {
					int k = (x << nn) + a[j].id;
					if (f[k] + a[j].c < F) F = f[k] + a[j].c,G = 0;
					if (f[k] + a[j].c == F) G = add(G + g[k]);
					j ++;
				}
				if (f[to] > F) f[to] = F,g[to] = G;
				else if (f[to] == F) g[to] = add(g[to] + G);
			}
		}
	}
	printf("%d %d",f[S - 1],g[S - 1]);
}

Details

answer.code: In function ‘int main()’:
answer.code:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%d%d",&n,&W);
      |         ~~~~~^~~~~~~~~~~~~~
answer.code:15:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         for (int i = 0; i < n; i ++) scanf("%d%d",&e[i].w,&e[i].c);
      |                                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<Node, std::allocator<Node> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = Node]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/queue:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~