SacredSpear's blog

By SacredSpear, history, 2 days ago, In English

my logic is first i will check if the entire vector is of 0s ,if yes then i just output 1 to n but otherwise i check if there are zeros on the left of the array and right of the array and perform operations accordingly ,u can easily see from my code

311920616

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

»
2 days ago, # |
  Vote: I like it +1 Vote: I do not like it

Here's my simple solution

void solve() {
    int n; cin >> n;
    vector<int> v(n);
    int z = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        z += v[i] == 0;
    }
 
    if(!z) {
        cout << "1\n";
        cout << "1 " << n << "\n";
    } else {
        if(v[0] != 0) {
            cout << "2\n";
            cout << "2 " << n << "\n";
            cout << "1 2\n";
        } else if(v[n-1] != 0) {
            cout << "2\n";
            cout << "1 " << n-1 << "\n";
            cout << "1 2\n";
        } else {
            cout << "3\n";
            cout << "1 2\n";
            cout << "2 " << n-1 << "\n";
            cout << "1 2\n";
        }
    }
}
  • »
    »
    2 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Sometimes ,when i look at my code ,i wonder if i have autism...

    thanks though ,crazy how we though of the same thing(almost) but my method was just chaos