提出 #35722760
ソースコード 拡げる
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int n;
char a[MAXN + 1];
char b[MAXN + 1];
char ans[MAXN + 1];
bool solve() {
REP(i, n) ans[i] = '?'; ans[n] = '\0';
vector<int> diff;
REP(i, n) if (a[i] == b[i]) ans[i] = '0'; else diff.PB(i);
if (SZ(diff) % 2 != 0) return false;
int want = SZ(diff) / 2, cnta = 0, cntb = 0;
for (int idx : diff) {
if (cnta == want) ans[idx] = b[idx], ++cntb;
else if (cntb == want) ans[idx] = a[idx], ++cnta;
else if (a[idx] == '0') ans[idx] = '0', ++cnta;
else ans[idx] = '0', ++cntb;
}
return true;
}
void run() {
scanf("%d", &n);
scanf("%s", a);
scanf("%s", b);
if (!solve()) { printf("-1\n"); return; }
printf("%s\n", ans);
}
int main() {
run();
return 0;
}
提出情報
コンパイルエラー
./Main.cpp: In function ‘bool solve()’:
./Main.cpp:25:20: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
25 | #define FOR(i,a,b) for(int i=(a);i<(b);++i)
| ^~~
./Main.cpp:26:18: note: in expansion of macro ‘FOR’
26 | #define REP(i,n) FOR(i,0,n)
| ^~~
./Main.cpp:43:2: note: in expansion of macro ‘REP’
43 | REP(i, n) ans[i] = '?'; ans[n] = '\0';
| ^~~
./Main.cpp:43:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
43 | REP(i, n) ans[i] = '?'; ans[n] = '\0';
| ^~~
./Main.cpp: In function ‘void run()’:
./Main.cpp:58:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
58 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
./Main.cpp:59:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
59 | scanf("%s", a);
| ~~~~~^~~~~~~~~
./Main.cpp:60:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
60 | scanf("%s", b);
| ~~~~~^~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
300 / 300 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
example0.txt, example1.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, example0.txt, example1.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 000.txt |
AC |
8 ms |
3656 KiB |
| 001.txt |
AC |
7 ms |
4180 KiB |
| 002.txt |
AC |
5 ms |
4224 KiB |
| 003.txt |
AC |
8 ms |
4812 KiB |
| 004.txt |
AC |
8 ms |
4836 KiB |
| 005.txt |
AC |
9 ms |
4900 KiB |
| 006.txt |
AC |
6 ms |
4116 KiB |
| 007.txt |
AC |
8 ms |
4448 KiB |
| 008.txt |
AC |
7 ms |
3876 KiB |
| 009.txt |
AC |
10 ms |
4312 KiB |
| 010.txt |
AC |
7 ms |
4444 KiB |
| 011.txt |
AC |
8 ms |
4420 KiB |
| 012.txt |
AC |
12 ms |
4444 KiB |
| 013.txt |
AC |
7 ms |
4440 KiB |
| 014.txt |
AC |
11 ms |
4368 KiB |
| 015.txt |
AC |
8 ms |
4860 KiB |
| 016.txt |
AC |
12 ms |
4836 KiB |
| 017.txt |
AC |
9 ms |
4776 KiB |
| 018.txt |
AC |
9 ms |
4840 KiB |
| 019.txt |
AC |
9 ms |
4840 KiB |
| 020.txt |
AC |
7 ms |
4776 KiB |
| 021.txt |
AC |
10 ms |
4836 KiB |
| 022.txt |
AC |
11 ms |
4832 KiB |
| 023.txt |
AC |
8 ms |
4888 KiB |
| 024.txt |
AC |
10 ms |
4704 KiB |
| example0.txt |
AC |
3 ms |
3580 KiB |
| example1.txt |
AC |
2 ms |
3620 KiB |