ã¡ããã¨æ´çããã®ã¯å¤§å¤ã ãè½ã¡çãã¦æ´çãããã
åé¡æ¦è¦
é·ã ã®æåå ãä¸ããããã ã "11/22 æåå" ã§ãããã©ãããå¤å®ããã
11/22 æååã§ããã¨ã¯ãæå 1, /, 2 ããã®é ã«ä¸¦ãã§ãã¦ã1 㨠2 ã®åæ°ãçãããã®ãããã
èãããã¨
0-indexed ã§èãããã¨ã«ããããã¤ã¾ããæåå ã®å é ã®æå㯠0 çªç®ã§ããã¨èãããã¨ã«ããã
ãã®ã¨ããè¦ãã¦ããã¨ä¾¿å©ãªãã¨ã¨ãã¦ãé·ã ã®æååã®çãä¸ã®æåã¯
- ãå¥æ°ã®ã¨ãï¼
N / 2
ï¼ ã 2 ã§å²ã£ãåï¼ - ãå¶æ°ã®ã¨ãï¼
N / 2
ã¨N / 2 + 1
ã§åå¾ã§ããã ã®å¶å¥ã«ãããããããN / 2
ãçãä¸ã ãã¨è¦ãã¦ããã¨ä¾¿å©ã ï¼ï¼ï¼ãããã§ã¯ããã®å¤ã ã¨ãã¦ãããã
ãã¦ãããããã¨æ¬¡ã®ããã«å¤å®ã§ããã
- ãããã ãå¶æ°ã®ã¨ãï¼"No"
- ã®ããããã«ã¤ãã¦
S[i] != '1'
ã®ã¨ãï¼"No" S[m] != '/'
ã®ã¨ãï¼"No"- ã®ããããã«ã¤ãã¦
S[i] != '2'
ã®ã¨ãï¼"No"
ãã®å¦ç㯠for
æãç¨ãã¦å®è¡ã§ããã
ã³ã¼ã
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; if (N % 2 == 0) { // ããããæåãµã¤ãºãå¶æ°ã®å ´åã¯ãã¡ cout << "No" << endl; return 0; } bool res = true; int mid = N / 2; // çãä¸ã®æåã®æ·»å for (int i = 0; i < mid; i++) if (S[i] != '1') res = false; if (S[mid] != '/') res = false; for (int i = mid+1; i < N; i++) if (S[i] != '2') res = false; if (res) cout << "Yes" << endl; else cout << "No" << endl; }