QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395511#4377. BackpackCMingTL 0ms0kbC++141.1kb2024-04-21 15:43:002024-04-21 15:43:01

Judging History

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

  • [2024-04-21 15:43:01]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-04-21 15:43:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
// #define int LL
// #define BOOL
const int N = 1024;
#ifdef BOOL
bool solve()
#else
void solve()
#endif
{
    int n, m; cin >> n >> m;
    vector<int> v(n + 1), w(n + 1);
    for(int i = 1; i <= n; i++) cin >> v[i] >> w[i];
    
    vector<bitset<N> > f(N);
    f[0][0] = 1;

    for(int i = 1; i <= n; i++)
	{
		// cout << "i = " << i << "---------\n";
        for(int k = 0; k < N; k++)
		{
        	for(int j = m; j >= v[i]; j--)
                f[k] |= (f[k ^ w[i]] >> (j - v[i])) << j;
			// cout << k << ":" << f[k] << "\n";
		}

	}


    for(int i = N - 1; i >= 0; i--)
        if(f[i].count())
        {
            cout << i << '\n';
            break;
        }
}

signed main()
{
	//freopen("D:\\VSC\\00\\in.txt","rt",stdin);
	//freopen("D:\\VSC\\00\\out.txt","wt",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t--)
	{
		#ifdef BOOL
		if(solve()) cout << "YES\n";
		else cout << "NO\n";
		#else
		solve();
		#endif
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

10
1023 401
179 441
416 951
420 984
1013 984
683 914
407 984
96 523
374 190
974 190
739 441
518 523
194 984
415 523
149 441
235 984
809 441
469 441
436 919
437 919
7 919
818 984
962 190
37 919
371 523
417 914
431 914
213 190
340 441
254 919
223 951
123 190
339 951
322 441
218 441
284 919
533 190
187...

output:


result: