rStarx's blog

By rStarx, history, 2 years ago, In English

This code generates '63' as the output for test case 7 of problem https://codeforces.com/problemset/problem/1616/C on my local machine but generates '64' when the codeforces server run it. How is this possible?

#include <bits/stdc++.h>
using namespace std;
#define int     int64_t
#define IOS     ios::sync_with_stdio(0); cin.tie(0);
 
 
signed main() {
    IOS;
    int t; cin >> t;
    while(t--) {
        // cout << "NEW TEST : " << t << "\n";
        int n; cin >> n;
        vector<double> a(n);
        for(auto &num : a) {
            cin >> num;
        }
        int gans = n + 2;
        for(int i=0;i<n;i++) {
            for(int j=i+1;j<n;j++) {
                
                
                double u = a[i];
                double v = a[j];
                double d = (v - u) / (j - i);
                int lans = 0;
                vector<double> new_array(n);
                new_array[i] = u;
                new_array[j] = v;
                for(int k=0;k<n;k++) {
                    if(k == i || k == j)
                        continue;
                    new_array[k] = u + (k - i) * d;
                }
                for(int k=0;k<n;k++) {
                    if(a[k] != new_array[k]) {
                        lans += 1;
                    }
                }
                gans = min(lans, gans);
            }
        }
        if(gans == (n + 2)) {
            gans = 0;
        }
        cout << gans << '\n';
    }
}
  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?