QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186840#6794. Sequence to SequencezhoukangyangWA 185ms6044kbC++111.4kb2023-09-24 12:26:342023-09-24 12:26:35

Judging History

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

  • [2023-09-24 12:26:35]
  • 评测
  • 测评结果:WA
  • 用时:185ms
  • 内存:6044kb
  • [2023-09-24 12:26:34]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long 
#define vi vector < int > 
#define sz(a) ((int) (a).size())
#define ll long long 
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a)) 
using namespace std;
const int N = 1 << 20;
int n;
int a[N], b[N];
ll dp[1 << 3], ndp[1 << 3];
void Main() {
	cin >> n;
	L(i, 1, n) {
		cin >> a[i];
	}
	L(i, 1, n) {
		cin >> b[i];
	}
	me(dp, -0x3f);
	dp[0] = 0;
	L(i, 1, n) {
		if(!a[i]) {
			if(b[i]) {
				cout << "-1\n";
				break;
			}
			continue;
		}
		me(ndp, -0x3f);
		L(s, -1, 1) {
			if(b[i] == 0 && s != 0) continue;
			L(w, s - 1, s + 1) if((b[i] > 0 && w <= 0) || (!b[i] && w >= 0)) {
				ll add = (b[i] - a[i]) * s;
				if(b[i] == 0) add += a[i] * w;
				else add += (a[i] - 1) * w;
				
				int v[3] = {w - s, s, -s};
				L(S, 0, (1 << 3) - 1) {
					int ok = 1, go = 0;
					L(j, 0, 2) {
						int SUM = max((S >> j & 1) + v[j], 0);
						if(SUM > 1) {
							ok = 0;
						} else if(SUM) {
							go |= 1 << j;
						}
					}
					if(ok) {
						ndp[go] = max(ndp[go], dp[S] + add);
					}
				}
			}
		}
		swap(dp, ndp);
	}
	cout << *max_element(dp, dp + 8) << '\n';
}
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t; cin >> t; while(t--) Main();
	return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5648kb

input:

2
5
1 1 1 1 1
2 0 2 0 2
7
3 1 2 3 2 1 4
2 0 0 0 0 0 2

output:

3
3

result:

ok 2 tokens

Test #2:

score: -100
Wrong Answer
time: 185ms
memory: 6044kb

input:

110121
5
0 0 0 0 0
1 4 5 4 1
5
1 0 0 0 0
0 6 8 6 1
5
2 0 0 0 0
4 4 1 3 6
5
3 0 0 0 0
5 1 1 7 6
5
4 0 0 0 0
6 8 7 0 8
5
5 0 0 0 0
5 9 7 7 5
5
6 0 0 0 0
9 2 2 8 0
5
7 0 0 0 0
9 4 7 0 9
5
8 0 0 0 0
6 7 3 7 5
5
9 0 0 0 0
4 0 9 1 4
5
0 1 0 0 0
0 6 6 3 0
5
1 1 0 0 0
3 4 3 4 9
5
2 1 0 0 0
0 4 0 1 4
5
3 1 0...

output:

-1
0
-1
1
-1
2
-1
2
-1
2
-1
0
-1
3
-1
2
-1
2
-1
5
-1
5
-1
3
-1
5
-1
3
-1
7
-1
10
-1
11
-1
13
-1
8
-1
10
-1
0
-1
6
-1
2
-1
4
-1
7
-1
4
-1
3
-1
14
-1
4
-1
15
-1
0
-1
2
-1
4
-1
4
-1
7
-1
8
-1
1
-1
4
-1
2
-1
11
-1
0
-1
6
-1
5
-1
3
-1
2
-1
4
-1
4
-1
5
-1
4
-1
4
-1
0
-1
4
-1
10
-1
6
-1
4
-1
3
-1
6
-1
2
-1...

result:

wrong answer 2nd words differ - expected: '-1', found: '0'