fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. #define dbg(var) cout<<#var<<"="<<var<<" "
  4. #define nl cout<<"\n"
  5. #define fr(i,n) for(int i=0;i<n;i++)
  6. #define rep(i,a,n) for(int i=a;i<=n;i++)
  7. #define vi vector<int>
  8. #define vvi vector<vi>
  9. #define pb push_back
  10. #define fa(v) for(auto &i:v)
  11. #define all(v) v.begin(),v.end()
  12. #define sz(v) (int)(v.size())
  13. // #define int long long
  14. #define kill(x) {cout << x << "\n"; return;}
  15. #define debug(...) fprintf(stdout, __VA_ARGS__), fflush(stdout)
  16. #define time__(d)for(long blockTime=0;(blockTime==0?(blockTime=clock())!=0:false); debug("%s:%.4fs\n",d,(double)(clock()-blockTime)/CLOCKS_PER_SEC))
  17. const int N = 10000;
  18. int arr[N][N];
  19.  
  20. void solve(){
  21.  
  22. for(int i = 0 ; i < N; i++)
  23. for(int j = 0; j < N; j++)
  24. arr[i][j] = rand() % N;
  25. time__("correct order"){
  26. int sm = 0;
  27. for(int i = 0 ; i < N; i++){
  28. for(int j = 0; j < N; j++){
  29. sm += arr[i][j];
  30. }
  31. }
  32. cout << sm << "\n";
  33. }
  34. time__("incorrect order"){
  35. int sm = 0;
  36. for(int j = 0; j < N; j++){
  37. for(int i = 0; i < N; i++){
  38. sm += arr[i][j];
  39. }
  40. }
  41. cout << sm << "\n";
  42. }
  43.  
  44.  
  45. }
  46. int32_t main()
  47. {
  48. ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  49. //int tst; cin >> tst; while(tst--)
  50. {
  51. solve();
  52. }
  53. }
Success #stdin #stdout 2.41s 394424KB
stdin
Standard input is empty
stdout
correct order:0.0466s
incorrect order:1.1843s
1732296625
1732296625