結果
問題 |
No.2018 X-Y-X
|
ユーザー |
![]() |
提出日時 | 2022-07-22 23:59:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 608 bytes |
コンパイル時間 | 2,243 ms |
コンパイル使用メモリ | 196,684 KB |
最終ジャッジ日時 | 2025-01-30 13:09:16 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 WA * 20 RE * 5 |
ソースコード
#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,B; for(int i=1;i<n;i++){ if(s[i-1]!=s[i]) A.push_back(i); if(t[i-1]!=t[i]) B.push_back(i); } int a=A.size(),b=B.size(); if(a!=b){ cout<<-1<<endl; return 0; } ll ans=0; rep(i,n) ans+=abs(A[i]-B[i]); cout<<ans<<endl; return 0; }