結果
| 問題 |
No.8057 A xor B = C
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-01 22:59:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,768 bytes |
| コンパイル時間 | 1,349 ms |
| コンパイル使用メモリ | 118,240 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 12:25:28 |
| 合計ジャッジ時間 | 1,681 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 4 RE * 1 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;
typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod
bool check(vector<int>& v){
int sz = v.size();
for(int i = 0; i < sz; ++i){
if(v[i]) return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s, t;
cin >> s >> t;
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
int ns = s.length(), nt = t.length();
vector<int> a(ns), b(nt);
for(int i = 0; i < ns; ++i) a[i] = s[i] - '0';
for(int i = 0; i < nt; ++i) b[i] = t[i] - '0';
vector<int> A;
while(check(a)){
A.push_back((a[0] % 2 == 0) ? 0 : 1);
if(a[0] % 2 != 0) --a[0];
a[0] /= 2;
for(int i = 1; i < ns; ++i){
int foo = 10 * a[i];
foo /= 2;
a[i - 1] += foo % 10;
a[i] = foo / 10;
}
}
vector<int> B;
while(check(b)){
B.push_back((b[0] % 2 == 0) ? 0 : 1);
if(b[0] % 2 != 0) --b[0];
b[0] /= 2;
for(int i = 1; i < nt; ++i){
int foo = 10 * b[i];
foo /= 2;
b[i - 1] += foo % 10;
b[i] = foo / 10;
}
}
int na = A.size(), nb = B.size();
if(na > nb) swap(A, B), swap(na, nb);
vector<int> ans(nb);
for(int i = 0; i < na; ++i) ans[i] = A[i] ^ B[i];
for(int i = na; i < nb; ++i) ans[i] = B[i];
vector<int> ans2(10000, 0);
int digit_cnt = 1, digit_cnt2 = 1;
vector<int> pow2(10000, 0);
pow2[0] = 1;
if(ans[0]) ans2[0] = 1;
for(int i = 1; i < ans.size(); ++i){
vector<int> hoge(10000, 0);
for(int j = 0; j < digit_cnt; ++j){
int foo = pow2[j] * 2;
hoge[j] += foo % 10;
int bar = hoge[j];
hoge[j] = bar % 10;
bar /= 10;
foo /= 10;
foo += bar;
int add = 1;
while(foo){
hoge[j + add] += foo % 10;
int bar2 = hoge[j + add];
hoge[j + add] = bar2 % 10;
bar2 /= 10;
foo /= 10;
foo += bar2;
chmax(digit_cnt, j + add + 1);
++add;
}
}
pow2 = hoge;
digit_cnt2 = digit_cnt;
for(int j = 0; j < digit_cnt2; ++j){
ans2[j] += pow2[j];
int foo = ans2[j];
ans2[j] = foo % 10;
foo /= 10;
int add = 1;
while(foo){
ans2[j + add] += foo % 10;
int bar = ans2[j + add];
ans2[j + add] = bar % 10;
bar /= 10;
foo /= 10;
foo += bar;
chmax(digit_cnt2, j + add + 1);
++add;
}
}
}
for(int i = digit_cnt2 - 1; i >= 0; --i) cout << ans2[i];
cout << endl;
}