Arcer's blog

By Arcer, history, 6 weeks ago, In English

I was trying 893C - Rumor. My submission is 367279083 in C++. I got a WA8, but I don't understand why. Someone please help. Code:

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, m;
    long long r = 0;
    cin >> n >> m;
    vector<int> v(n);
    vector<pair<int, bool>> x(n, {0, false});
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) x[i].first = i + 1;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (v[b - 1] < v[a - 1]) x[a - 1].first = b;
        else x[b - 1].first = a;
    }
    map<int, int> ma;
    vector<int> fi;
    for (int i = 0; i < n; i++) {
        int ind = i;
        if (x[i].second == false) {
            while (x[ind].first != ind + 1) {
                x[ind].second = true;
                ind = x[ind].first - 1;
            }
            ma[ind]++;
            if (ma[ind] == 1) fi.push_back(ind);
        }
    }
    for (int i = 0; i < fi.size(); i++) r += v[fi[i]];
    cout << r << endl;
}

int main() {
    int t = 1;
    //cin >> t;
    while (t--) solve();
}

Full text and comments »

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

By Arcer, history, 3 months ago, In English

I was trying 1692E - Binary Deque using C++, I am getting WA on test 2. Submission: 359959283

Logic: I have stored the amount of operations it would take to remove the '1' on every index from left end of the array in one vector v1 and from the right side of the array in another vector v2. Then I have calculated the number of '1's to be removed in d. I iterated till d = 0 to get the nearest '1' from each end of the vector by using f and b to store the amount of elements removed already from left and right side of the vector respectively. While iterating, I have added the least amount of operations from each end to r and at last, printed r.

Please tell me what is wrong with the logic and the code

Code:

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, s;
    cin >> n >> s;
    vector<int> v1, v2;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == 1) {
            v1.push_back(i + 1);
            v2.push_back(n - i);
        }
    }
    int d = v1.size() - s, r = 0, f = 0, b = 0;
    if (d < 0) cout << -1 << endl;
    else {
        while (d != 0) {
            if (v1[0] - f < v2[v2.size() - 1] - b) {
                r += v1[0] - f;
                f = v1[0];
                v1.erase(v1.begin());
                v2.erase(v2.begin());
            } else {
                r += v2[v2.size() - 1] - b;
                b = v2[v2.size() - 1];
                v1.pop_back();
                v2.pop_back();
            }
            d--;
        }
        cout << r << endl;
    }
}

int main() {
    int t = 1;
    cin >> t;
    while (t--) solve();
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Arcer, history, 4 months ago, In English

Everyone, I am "Newbie" titled, but as it was new year, just for fun, i changed my title to Legendary Grandmaster, I thought it would reset back to default after 10th Jan, but it didnt.

Please help me, I want my original title back, what to do?

Edit: The problem is solved

Full text and comments »

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

By Arcer, history, 4 months ago, In English

I was just trying to solve 1985C - Good Prefixes using C++ and this is my code, i dont know why but this code doesnt work for specific testcases. Please help me find the mistake.

My code:

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, c = 0;
    cin >> n;
    vector<long long int> v(n), s(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i == 0) s[i] = v[i];
        else s[i] = s[i - 1] + v[i];
    }
    for (int i = 1; i < n; i++) if (find(v.begin(), v.begin() + i + 1, s[i] / 2) != v.end() && s[i] % 2 == 0) c++;
    if (v[0] == 0) c++;
    cout << c << endl;
}

int main() {
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}

Full text and comments »

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

By Arcer, history, 23 months ago, In English

I was just trying the problem 1941C - Rudolf and the Ugly String and the language used was C++. This is my code, 263228103

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t, n, c = 0;
    cin >> t;
    string s, s1 = "map", s2 = "pie", s3 = "mapie";
    for (int i = 0; i < t; i++) {
        cin >> n;
        cin >> s;
        for (int j = 0; j < n - 2; j++) {
            if (s.find(s3) != string::npos) {
                c++;
                s.erase(s.begin() + s.find(s3) + 2);
            }
            if (s.find(s1) != string::npos) {
                c++;
                s.erase(s.begin() + s.find(s1) + 1);
            }
            if (s.find(s2) != string::npos) {
                c++;
                s.erase(s.begin() + s.find(s2) + 1);
            }
        }
        cout << c << endl;
        c = 0;
    }
}

It passed all my tests but somehow it gets a Wrong answer at testcase 3. Can someone please figure out the mistake made?

Full text and comments »

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