제출 #1166713

#제출 시각아이디문제언어결과실행 시간메모리
1166713AzeTurk810Election (BOI18_election)C++20
0 / 100
1 ms320 KiB
// Telebe of adicto yani AzeTurk810
// Why i am not a teacher?  ?(idea from Ayxan007)
#include <bits/stdc++.h>

using namespace std;
using ll= int64_t;
using ull=unsigned int64_t;

# define mpll map<ll,ll>
# define umpll unordered_map<ll,ll>
# define vv vector<vector
# define vint vector<int>
# define vull vector<unsigned long long>
# define sint set<int>
# define vpri vector<pair<int,int>>
# define vll vector<long long>
# define vbl vector<bool>
# define vvint vector<vector<int>>
# define vvll vector<vector<long long>>

/* Other defines*/
# define qint queue<int>

//# define endl '\n'
# define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define range(a,b,c) for(int i=a;i<b;i+=c)
# define ranger(a,b,c) for(int r=a;r<b;r+=c)
# define arange(a,b,c) for(int i=a;i>b;i-=c)
# define bend(x) (x).begin(),(x).end()
# define pb push_back
# define sortv(v) sort((v).begin() , (v).end());
# define fori(x) for(int i=0;i<x;i++)
# define forj(y) for(int j=0;j<y;j++)
# define fori1(x) for(int i=1;i<=x;i++)
# define forj1(y) for(int j=1;j<=y;j++)
# define forn(x,c) for(int i=0;i<n;i+=c)
# define ff first
# define ss second
# define INFi 1e15
# define INFll 1e18
# define printfprs(v) for(int alma = 0;alma<(v).size();alma++){cout<<(v)[alma].ff<< ' '<<(v)[alma].ss<<endl;};
# define printfv(v) {for(int alol = 0 ; alol < (v).size() ; alol++){cout<<(v)[alol]<<' ';}cout << endl;}
# define ln '\n'
//# define T int_fast32_t
# define int ll


const int maxN = 1e5 + 123 , maxK = 19;
int n;

void solve() {
    string s;cin >> n;
    cin >> s;
    int q;
    cin >> q;
    while(q--) {
        int l , r ;
        cin >> l >> r;
        int cnt[2];
        string ss = s;
        cnt[1] = cnt[0] = 0;
        l--;r--;
        int res =0;
        for(int i = l ; i <= r; i++) {
            // cout << ss[i];
            cnt[(ss[i] == 'C'?0:1)]++;
            if(cnt[1] > cnt[0] && ss[i] == 'T') {
                ss[i] = 'X';
                cnt[1]--;
                res++;
            }
        }
        cnt[1] = cnt[0] = 0;
        for(int i= r ; i >= l;i--) {
            if(ss[i] == 'X') continue;
            cnt[(ss[i] == 'C'?0:1)]++;
            if(cnt[1] > cnt[0] && ss[i] == 'T') {
                ss[i] = 'X';
                cnt[1]--;
                res++;
            }
        }
        // cout << res << ln;
        res = 0;
        fori(n) {
            if(s[i] != ss[i]) res++;
        }
        cout << res << ln;
    }
}
signed main()
{
    fastio;
    int t = 1;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("log.txt", "w", stderr);
    #endif
        // cout << 1 <<endl;
    // cin >> t;
    // cout << t << endl;
    while(t--) {
        solve();
    }
    return 0;
}

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

election.cpp: In function 'int main()':
election.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen("log.txt", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...