結果
問題 |
No.2018 X-Y-X
|
ユーザー |
![]() |
提出日時 | 2022-07-23 00:42:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 826 bytes |
コンパイル時間 | 2,159 ms |
コンパイル使用メモリ | 197,352 KB |
最終ジャッジ日時 | 2025-01-30 13:11:15 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; string s,t; cin>>n>>s>>t; if(s[0]!=t[0] || s[n-1]!=t[n-1]){ cout<<-1<<endl; return 0; } vector<int> A(n-1),B(n-1); rep(i,n-1){ if(s[i]==s[i+1]) A[i]=0; else A[i]=1; if(t[i]==t[i+1]) B[i]=0; else B[i]=1; } int c1=0,c2=0; rep(i,n-1){ if(i%2) A[i]^=1,B[i]^=1; if(A[i]) c1++; if(B[i]) c2++; } if(c1!=c2){ cout<<-1<<endl; return 0; } ll ans=0; vector<int> C,D; rep(i,n-1){ if(A[i]) C.push_back(i); if(B[i]) D.push_back(i); } int c=C.size(); rep(i,c){ ans+=abs(C[i]-D[i]); } cout<<ans<<endl; return 0; }