transfermarket's blog

By transfermarket, 2 months ago, In English

252263436

This code memset 3e5 element every testcase.

With 10^4 test case, the number of operation is equal to 3*10^9.

So why does it run in 1.5s. As I know, C++ run 3*10^8 operation every second.

Is it because CF judge is fast?

Note that this is not because the test is weak, test case 3 has 10000 test case. Still, the code can pass this test

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

»
2 months ago, # |
Rev. 4   Vote: I like it +16 Vote: I do not like it

$$$3*10^8$$$ operations per second is a good "rule-of-thumb" guideline. In practice things are more complicated and it depends on the operations.

Generally memset is extremely fast, even if linear asymptotically. Depending on the compiler/architecture it may do less operations (if zeroing chunks of bytes at once is supported by the architecture), or it may just do the operations much faster by levering some low-level optimizations due to the simplicity of the operation.

In a nutshell, memseting $$$3*10^9$$$ in 1.6s sounds very plausible.