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

Автор alessandrosolbiati, история, 7 лет назад, По-английски

The following code (problem B of last contest) give different outputs if compiled with different versions of C++11/C++14, only on this specific input

42147 412393322

why is that?

(I included the header only for reference)


//START HEADER --------------------------------------------- using namespace std; #define int int64_t #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define EPS 1e-7 #define INF 1e9 #define foor(n) for (int i=0;i<n;i++) #define fooor(a,n) for (int i=a;i<n;i++) #define per(a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define ssz(x) ((int)(x).size()) #define pc(x) putchar(x) //#define PI acos(-1); typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<pair<int,int>> vii; typedef vector<vector<int>> vvi; typedef long long ll; typedef unsigned long long ull; const ll mod=1000000007; ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} namespace ib {char b[100];} inline void pi(int x){ //fasto if(x==0) {pc(48); return;} if(x<0) {pc('-'); x=-x;} char *s=ib::b; while(x) *(++s)=x%10,x/=10; while(s!=ib::b) pc((*(s--))+48); } inline void ri(int &x){ //fasti x=0; static char c; bool t(0); while(c=getchar(),c<'0'||c>'9') if(c=='-') t=1; else t=0; do x=(x<<1)+(x<<3)+c-'0'; while(c=getchar(),c>='0'&&c<='9'); if(t) x=-x; } //#define cerr if(0)cerr #define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); } vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n'; err(++it, args...); } // FINISH HEADER --------------------------------------------------------------------------------------- string itoa(int n){ string res = ""; int r=-1; while(n/10!=0){ r=n%10; res+=char(r+'0'); n/=10; } r=n%10; res+=char(r+'0'); reverse(all(res)); return res; } int aatoi(string s){ int res=0; foor(ssz(s)){ res+=(int)(s[i]-'0')*pow(10, i); } // error(s,res); return res; } int32_t main(){ int n,m; cin >> n >> m; int res=0; foor(n+1){ string s = itoa(i); string r = s; reverse(all(r)); s=s+r; //error(aatoi(s.c_str())); res+=aatoi(s.c_str()); } return cout<<res% (1ll * m),0; }
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

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

Answer is here http://codeforces.net/blog/entry/54610 and don't reinvent the standard library badly.