結果
| 問題 |
No.1209 XOR Into You
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-23 17:37:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,230 bytes |
| コンパイル時間 | 590 ms |
| コンパイル使用メモリ | 44,416 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2024-06-27 22:50:28 |
| 合計ジャッジ時間 | 6,410 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:45:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
main.cpp:46:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <utility>
#include <string.h>
#include <set>
using namespace std;
#define F first
#define S second
typedef long long int ll;
constexpr int kN = int(1E5 + 10);
int ABS(int n) {return n >= 0 ? n : -n;}
struct BIT {
int val[kN];
void init() {memset(val, 0, sizeof(val));}
void add(int pos) {
while (pos < kN) {
val[pos]++;
pos += pos & -pos;
}
return ;
}
int ask(int pos) {
int ans = 0;
while (pos) {
ans += val[pos];
pos ^= pos & -pos;
}
return ans;
}
};
int a[kN], b[kN], difa[kN], difb[kN];
set<pair<int, int>> se;
BIT bit;
int main() {
int n;
ll ans = 0;
set<pair<int, int>>::iterator u;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
for (int i = 2; i <= n; i++) difa[i] = a[i] ^ a[i - 1];
for (int i = 2; i <= n; i++) difb[i] = b[i] ^ b[i - 1];
for (int i = 2; i <= n; i++) se.insert({difa[i], i});
bit.init();
for (int i = 2; i <= n; i++) {
u = se.lower_bound({difb[i], 0});
if (u == se.end() || u -> F != difb[i]) {
printf("-1\n");
return 0;
}
else {
ans += ABS(u -> S - bit.ask(u -> S) - 2);
bit.add(u -> S);
se.erase(u);
}
}
printf("%lld\n", ans);
}