#include <iostream>
#include <stack>
#include <ctime>
#include <vector>
std:: stack < clock_t > tictoc_stack;
void tic( ) {
tictoc_stack.push ( clock ( ) ) ;
}
void toc( ) {
std:: cout << "Time elapsed: "
<< ( ( double ) ( clock ( ) - tictoc_stack.top ( ) ) ) / CLOCKS_PER_SEC
<< std:: endl ;
tictoc_stack.pop ( ) ;
}
using namespace std;
int main( ) {
int sizes[ ] = { 5 , 10 , 20 , 30 , 40 , 50 , 100 , 200 , 300 , 400 , 500 , 1000 } ;
for ( int k = 0 ; k < 12 ; ++ k) {
int SIZE = sizes[ k] ;
cout << "SIZE " << SIZE << endl;
vector< vector< int > > v( SIZE, std:: vector < int > ( SIZE) ) ;
tic( ) ;
for ( int t = 0 ; t < 1000 ; ++ t) {
for ( int i = 0 ; i < SIZE; ++ i) {
for ( int j = 0 ; j < SIZE; ++ j) {
v[ i] [ j] = v[ i] [ j] + 5 ;
}
}
}
toc( ) ;
vector< vector< int > > v3( SIZE, std:: vector < int > ( SIZE) ) ;
tic( ) ;
for ( int t = 0 ; t < 1000 ; ++ t) {
for ( int i = 0 ; i < SIZE; ++ i) {
for ( int j = 0 ; j < SIZE; ++ j) {
v3[ j] [ i] = v3[ j] [ i] + 5 ;
}
}
}
toc( ) ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnN0ZDo6c3RhY2s8Y2xvY2tfdD4gdGljdG9jX3N0YWNrOwoKdm9pZCB0aWMoKSB7CiAgICB0aWN0b2Nfc3RhY2sucHVzaChjbG9jaygpKTsKfQoKdm9pZCB0b2MoKSB7CiAgICBzdGQ6OmNvdXQgPDwgIlRpbWUgZWxhcHNlZDogIgogICAgPDwgKChkb3VibGUpKGNsb2NrKCkgLSB0aWN0b2Nfc3RhY2sudG9wKCkpKSAvIENMT0NLU19QRVJfU0VDCiAgICA8PCBzdGQ6OmVuZGw7CiAgICB0aWN0b2Nfc3RhY2sucG9wKCk7Cn0KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIAogICAgaW50IHNpemVzW10gPSB7NSwgMTAsIDIwLCAzMCwgNDAsIDUwLCAxMDAsIDIwMCwgMzAwLCA0MDAsIDUwMCwgMTAwMH07CiAgICAKICAgIGZvciAoaW50IGsgPSAwOyBrIDwgMTI7ICsraykgewogICAgICAgIAogICAgICAgIGludCBTSVpFID0gc2l6ZXNba107CiAgICAgICAgCiAgICAgICAgY291dCA8PCAiU0laRSAiIDw8IFNJWkUgPDwgZW5kbDsKICAgICAgICAKICAgICAgICB2ZWN0b3I8dmVjdG9yPGludD4gPiB2KFNJWkUsIHN0ZDo6dmVjdG9yPGludD4oU0laRSkpOwogICAgICAgIAogICAgICAgIHRpYygpOwogICAgICAgIAogICAgICAgIGZvciAoaW50IHQgPSAwOyB0IDwgMTAwMDsgKyt0KSB7CiAgICAgICAgICAgIAogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IFNJWkU7ICsraSkgewogICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBTSVpFOyArK2opIHsKICAgICAgICAgICAgICAgICAgICB2W2ldW2pdID0gdltpXVtqXSArIDU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgfQogICAgICAgIAogICAgICAgIHRvYygpOwoKICAgICAgICB2ZWN0b3I8dmVjdG9yPGludD4gPiB2MyhTSVpFLCBzdGQ6OnZlY3RvcjxpbnQ+KFNJWkUpKTsKCiAgICAgICAgCiAgICAgICAgdGljKCk7CiAgICAgICAgCiAgICAgICAgZm9yIChpbnQgdCA9IDA7IHQgPCAxMDAwOyArK3QpIHsKICAgICAgICAgICAgCiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgU0laRTsgKytpKSB7CiAgICAgICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IFNJWkU7ICsraikgewogICAgICAgICAgICAgICAgICAgIHYzW2pdW2ldID0gdjNbal1baV0gKyA1OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgIH0KICAgICAgICAKICAgICAgICB0b2MoKTsgICAgICAgIAogICAgICAgIAoKICAgICAgICAKICAgIH0KfQ==