답안 #894919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894919 2023-12-29T08:21:23 Z LeonaRaging Flip it and Stick it (CCO23_day2problem1) C++14
8 / 25
2 ms 1008 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb emplace_back
#define pf emplace_front
#define fi first
#define se second
#define T pair<int,int>
#define all(val) val.begin(), val.end()
#define SZ(val) (int)val.size()
#define db(val) "[" #val " = " << (val) << "] "

const int maxn = 3e5 + 4;
const int N = 16;
const int mod = 1e9 + 7;
const int INF = 1e9;

void coding() {
    if (fopen("inputf.in", "r")) {
        freopen("inputf.in", "r", stdin);
        freopen("outputf.out", "w", stdout);
        freopen("log.out", "w", stderr);
    }
    if (fopen(".INP", "r")) {
        freopen(".INP", "r", stdin);
        freopen(".OUT", "w", stdout);
    }
}

string s, t;

namespace sub1 {
    void Solve() {
        bool f = 0;
        for (int i = 0; i < SZ(s); i++)
            if (s[i] == '0')
                return cout << -1, void();
        cout << 0;
    }
}

namespace sub2 {
    void Solve() {
        int res = 0;
        for (int i = 0; i < SZ(s) - 1; i++)
            if (s[i] == '0' && s[i + 1] == '1')
                res++;
        cout << res;
    }
}

namespace sub3 {
    void Solve() {
        int cnt0 = 0, cnt1 = 0, res = 0;
        for (int i = 0; i < SZ(s); i++) {
            if (s[i] == '0') cnt0++;
            else cnt1++;
            if (i < SZ(s) - 1 && s[i] == '0' && s[i + 1] == '0') res++;
        }
        if (cnt0 > cnt1 + 1) return cout << -1, void();
        cout << res;
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    coding();
    cin >> s >> t;
    if (t[0] == '1') {
        for (int i = 0; i < SZ(t); i++)
            if (t[i] == '0') t[i] = '1';
            else t[i] = '0';
        for (int i = 0; i < SZ(s); i++)
            if (s[i] == '0') s[i] = '1';
            else s[i] = '0';
    }
    if (t == "0") sub1::Solve();
    if (t == "01") sub2::Solve();
    if (t == "00") sub3::Solve();
}

Compilation message

Main.cpp: In function 'void sub1::Solve()':
Main.cpp:35:14: warning: unused variable 'f' [-Wunused-variable]
   35 |         bool f = 0;
      |              ^
Main.cpp: In function 'void coding()':
Main.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("inputf.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("outputf.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("log.out", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 736 KB Output is correct
4 Correct 1 ms 740 KB Output is correct
5 Correct 1 ms 740 KB Output is correct
6 Correct 1 ms 740 KB Output is correct
7 Correct 1 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 740 KB Output is correct
7 Correct 1 ms 740 KB Output is correct
8 Correct 1 ms 740 KB Output is correct
9 Correct 1 ms 740 KB Output is correct
10 Correct 1 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 740 KB Output is correct
7 Correct 1 ms 740 KB Output is correct
8 Correct 1 ms 740 KB Output is correct
9 Correct 1 ms 740 KB Output is correct
10 Correct 1 ms 740 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 2 ms 1008 KB Output is correct
24 Correct 2 ms 896 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 984 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 984 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 888 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -