Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Badri41's blog

By Badri41, history, 5 hours ago, In English

Hello Codeforces,

I am beginner here I am having problems regarding the competitive programming helper extension and would appreciate some help regarding it.

When I run a testcase for example Anya and 1100 problem and for this problem my code is

bool check(string& s, int i)
{
    if (s[i] == '1' && s[i + 1] == '1' && s[i + 2] == '0' && s[i + 3] == '0')
        return true;
    return false;
}

void solve()
{
    string s; cin >> s;
    int q; cin >> q;
    int n = s.size();
    set<int> exists;
    for (int i = 0; i < n - 3; i++)
        if (check(s, i))
            exists.insert(i);
    while (q--)
    {
        int i; cin >> i; i--;
        char c; cin >> c;
        s[i] = c;
        for (int j = i - 3; j <= i; j++)
        {
            if (j < 0 || j + 3 >= n)
                continue;
            if (exists.find(j) != exists.end())
                exists.erase(j);
            if (check(s, j))
                exists.insert(j);
        }
        if (exists.size())
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    vector<map<int, int>> ls = { {{1, 2}}, {{3, 4}}, {{4, 5}} };

    for (const auto& m : ls) {  // Iterate over each map in the vector
        for (const auto& pair : m) {  // Iterate over each key-value pair in the map
            cout << pair.first << " " << pair.second << endl;
        }
    }
}

int main() {
    #ifdef DEBUG
        freopen("Error.txt", "w", stderr);
    #endif
        fastio();
        auto start1 = high_resolution_clock::now();
        int tt;
        cin>>tt;
        while(tt--) {solve();}
        auto stop1 = high_resolution_clock::now();
        auto duration = duration_cast<microseconds>(stop1 - start1);
    #ifdef DEBUG
        cerr << "Time: " << duration . count() / 1000 << endl;
    #endif
}

I am getting the following errors in my output

Errors while compiling:
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:1:9: warning: 'DEBUG' macro redefined [-Wmacro-redefined]
    1 | #define DEBUG
      |         ^
<command line>:1:9: note: previous definition is here
    1 | #define DEBUG 1
      |         ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:99:70: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
   99 | template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
      |                                                                      ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:100:67: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  100 | template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
      |                                                                   ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:101:72: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  101 | template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
      |                                                                        ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:102:75: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  102 | template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
      |                                                                           ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:102:82: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  102 | template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
      |                                                                                  ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:127:32: error: a space is required between consecutive right angle brackets (use '> >')
  127 |     std::vector<std::vector<int>> jump;
      |                                ^~
      |                                > >
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:137:16: error: expected expression
  137 |         jump = {std::vector<int>((int)v.size())};
      |                ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:160:22: error: a space is required between consecutive right angle brackets (use '> >')
  160 |     vector<vector<int>> adj;
      |                      ^~
      |                      > >
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:176:19: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  176 |         for(int e : adj[i]){
      |                   ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:234:24: error: a space is required between consecutive right angle brackets (use '> >')
  234 |     vector<map<int, int>> ls = { {{1, 2}}, {{3, 4}}, {{4, 5}} };
      |                        ^~
      |                        > >
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:234:27: error: non-aggregate type 'vector<map<int, int> >' cannot be initialized with an initializer list
  234 |     vector<map<int, int>> ls = { {{1, 2}}, {{3, 4}}, {{4, 5}} };
      |                           ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:236:16: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  236 |     for (const auto& m : ls) {  // Iterate over each map in the vector
      |                ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:236:24: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  236 |     for (const auto& m : ls) {  // Iterate over each map in the vector
      |                        ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:237:20: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  237 |         for (const auto& pair : m) {  // Iterate over each key-value pair in the map
      |                    ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:237:31: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  237 |         for (const auto& pair : m) {  // Iterate over each key-value pair in the map
      |                               ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:248:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  248 |         auto start1 = high_resolution_clock::now();
      |         ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:252:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  252 |         auto stop1 = high_resolution_clock::now();
      |         ^
/Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp:253:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  253 |         auto duration = duration_cast<microseconds>(stop1 - start1);
      |         ^
14 warnings and 5 errors generated.

I would highly appreciate any help.

  • Vote: I like it
  • -3
  • Vote: I do not like it

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

// this is the corrected code ~~~~~~~~~~~~~~~~~~

include <bits/stdc++.h>

using namespace std; using namespace chrono;

bool check(string& s, int i) { if (s[i] == '1' && s[i + 1] == '1' && s[i + 2] == '0' && s[i + 3] == '0') return true; return false; }

void solve() { string s; cin >> s; int q; cin >> q; int n = s.size(); set exists; for (int i = 0; i < n — 3; i++) if (check(s, i)) exists.insert(i); while (q--) { int i; cin >> i; i--; char c; cin >> c; s[i] = c; for (int j = i — 3; j <= i; j++) { if (j < 0 || j + 3 >= n) continue; if (exists.find(j) != exists.end()) exists.erase(j); if (check(s, j)) exists.insert(j); }

if (exists.size())
        cout << "YES\n";
    else
        cout << "NO\n";
}

}

int main() { #ifdef DEBUG freopen("Error.txt", "w", stderr); #endif

// Fast input/output
ios::sync_with_stdio(false); 
cin.tie(0);

// Time measurement (for debugging purposes)
auto start1 = high_resolution_clock::now();

int tt;
cin >> tt;  // Number of test cases
while (tt--) {
    solve();  // Solve each test case
}

// Measure time and print
auto stop1 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop1 - start1);

#ifdef DEBUG
    cerr << "Time: " << duration.count() / 1000 << " ms" << endl;
#endif

return 0;

} ~~~~~~~~~~~~~~~~~~~