結果
| 問題 |
No.2018 X-Y-X
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-07-22 22:45:45 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,240 bytes |
| コンパイル時間 | 2,812 ms |
| コンパイル使用メモリ | 114,668 KB |
| 最終ジャッジ日時 | 2025-01-30 12:51:11 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 WA * 5 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <atcoder/modint>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<1000000007>;
int main(){
int N; cin >> N;
string S; cin >> S;
vector<int> Sx(N-1);
rep(i,N-1) Sx[i] = (S[i] == S[i+1]) ? 0 : 1;
string T; cin >> T;
vector<int> Tx(N-1);
rep(i,N-1) Tx[i] = (T[i] == T[i+1]) ? 0 : 1;
if(S[0] != T[0]){ cout << "-1n"; return 0; }
if(S.back() != T.back()){ cout << "-1n"; return 0; }
N--;
rep(i,N) if(i%2==0) Sx[i] ^= 1;
rep(i,N) if(i%2==0) Tx[i] ^= 1;
vector<int> Si;
rep(i,N) if(Sx[i] == 0) Si.push_back(i);
vector<int> Ti;
rep(i,N) if(Tx[i] == 0) Ti.push_back(i);
if(Si.size() != Ti.size()){ cout << "-1\n"; return 0; }
i64 ans = 0;
rep(i,Si.size()) ans += abs(Si[i] - Ti[i]);
cout << ans << '\n';
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia