제출 #1128559

#제출 시각아이디문제언어결과실행 시간메모리
1128559ntdaccodeFlip it and Stick it (CCO23_day2problem1)C++20
4 / 25
2 ms720 KiB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define pb push_back

using namespace std;

typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;

const int M = 1e6 + 10;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
string s,t;
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  if(fopen("1.inp","r")) {
    freopen("1.inp","r",stdin);
    freopen("1.out","w",stdout);
  }

  #define task ""
  if(fopen(task".inp","r")) {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }

  cin >> s >> t;
  s = ' ' + s;
  t = ' ' + t;
  int n = s.size() - 1;
  int m = t.size() - 1;
  if(m == 1) {
    int ok = 0;
    for(int i = 1;i <= n; i++) if(s[i] == t[1]) ok = -1;
    cout << ok;
  }
  else {
    int kq = 0;
    if(t[1] != t[2]) {
      bool run = false;
      for(int i = 1;i <= n - 1; i++) {
        if(s[i] == t[1] && s[i + 1] == t[2] && !run) {
            run = true;
            kq++;
        }
        if(s[i] == t[2] && s[i + 1] == t[1] && run) run = false;
      }
      cout << kq ;
    }
    else {
      int cnt = 0;
      for(int i = 1;i <= n - 1; i++) {
          if(s[i] == t[1]) cnt--;
          else cnt++;
          if(s[i] == t[1] && s[i + 1] == t[1]) kq++;
      }
      if(s[n] != t[1]) cnt++;
      if(cnt < -1) cout << -1;
      else cout << kq;
    }
  }


}


컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int32_t main()':
Main.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...