Badri41's blog

By Badri41, history, 7 weeks 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.

Thank you for helping finally the issue is resolved, in vs code settings I added "-std=c++20" in the args section of extensions.

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it -12 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;

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

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Bro I don't want the corrected code, I want to know how to parse my cph judge so that it can run with auto key word and I can use range based for loop

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      use using namespace chrono; after using namespace std;
      and instead of fastio() use
      ios::sync_with_stdio(false); cin.tie(0);

    • »
      »
      »
      6 weeks ago, # ^ |
      Rev. 4   Vote: I like it 0 Vote: I do not like it

      What version of C++ are you on? It looks like the compiler doesn't support C++11.

      I'm not very familiar with Competitive Programming Helper. Did it install the compiler or did you install one separately? What compiler and what version is it? (It's just a VS code extension to parse inputs, right? I don't think it is the issue. Does the code work if you compile it otherwise?)

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Before I installed the Competitive Programming Helper extension I always wrote and compiled my code in C++20.

        -I installed the cph judge from vs code extensions it parses input and output using codeforces api from a ongoing problem and displays it in my vscode .cpp file, it can run testcases locally in my mac.

        -As for the compiler I use Apple clang version 16.0.0 which I installed using "brew install gcc"

        -yes the code works perfectly if I compile it otherwise as shown below ~~~~~ * Executing task: clang++ -std=c++20 -g /Users/badribishaldas/Desktop/Home/Coding/CPP/2036C.cpp -o /Users/badribishaldas/Desktop/Home/Coding/CPP/2036C * Terminal will be reused by tasks, press any key to close it. ~~~~~

        -The issue is When I run my file using the cph judge extension it throws the error which I wrote in the above blog

        Thank you for taking your time to address this issue.

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thank you for helping finally the issue is resolved, in vs code settings I added "-std=c++20" in the args section of extensions.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Badri41 (previous revision, new revision, compare).