Блог пользователя neat

Автор neat, история, 4 года назад, По-английски

76778492

#include <bits/stdc++.h> 
using namespace std;
int main() { 
  long long t, n, p;
  cin >> t; 
  while(t--) 
  { 
    p = 0;
    cin >> n; 
    for(int i=0; i<n; i++) 
      for(int j=0; j<n; j++) 
        for(int k = 0; k < n; k++) 
          for(int l = 0; l < n; l++) 
            for(int m = 0; m < n; m++)
              for(int o = 0; o < n; o++)
                p++;
    p -= p;
    cout << p + n << "\n";
  }
  return 0; 
  
}

Above is one of my Accepted submissions for problem 1339A — Filling Diamonds from Codeforces Round #633 (Div. 2). The answer for the problem is same as the input $$$n$$$ for each testcase. Its complexity is $$$O(n^6)$$$ per testcase. Here $$$1 <= n <= 10^9$$$. I am wondering how it passed all testcases. Kindly write your thoughts in the comments section.

  • Проголосовать: нравится
  • -13
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Wow! An unfortunate way to answer that question.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    Yes. I made such a submission after seeing an $$$O(n)$$$ per testcase solution getting Accepted. Was shocked to see my $$$O(n^6)$$$ per testcase solution also getting Accepted.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Surprising!

»
4 года назад, # |
  Проголосовать: нравится +55 Проголосовать: не нравится

its -O2 optimisation of the compiler.