alessandrosolbiati's blog

By alessandrosolbiati, 7 years ago, In English

TEMPLATE FUNCTIONS:

stdin = lambda type_ = "int", sep = " ": list(map(eval(type_), raw_input().split(sep)))
"""
>>> stdin()
1 2 3 4
>>>[1, 2, 3, 4]
"""

joint = lambda sep = " ", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args)
"""
>>> joint(" ", [1, 2])
'1 2'
>>> joint(" ", [1, 2], [2, 3])
'1 2 2 3'
"""

def iters(): return map(int(raw_input()))

PROBLEMS:

==================

http://mirror.codeforces.com/contest/988/problem/B

n = int(input())
a = sorted((input() for _ in range(n)), key=lambda x: len(x))
v = all(a[i] in a[i+1] for i in range(n-1))
print('YES\n'+"\n".join(a) if v else 'NO')

==================

http://mirror.codeforces.com/contest/994/problem/A

R = lambda: (int, input().split())
n, a, b = R(), R(), R()
print(' '.join(map(str, (x for x in a if x in b))))

==================

http://mirror.codeforces.com/contest/994/problem/B

R = lambda: map(int, input().split())
n, k = R(), 
v, t = [], [0]*n
for p, c, i in sorted(zip(R(), R(), range(n))):
    t[i] = sum(v)+c
    v += [c]
    v = sorted(v)[::-1]
    if len(v) > k:
        v.pop()
print(' '.join(map(str, t)))

==================

http://mirror.codeforces.com/contest/754/problem/A

n, a = int(input()), list(map(int, input().split()))
x = next((i for i, ai in enumerate(a) if ai), None) # find index of first non-zero elements in a
if x is None:
    print('NO')
elif sum(a):
    print('YES', 1, '1 {}'.format(n), sep='\n')
else:
    print('YES', 2, '1 {}'.format(x + 1), '{} {}'.format(x + 2, n), sep='\n')

==================

http://mirror.codeforces.com/contest/996/problem/B


import math n, a, m, res = int(input()), [*(map(int,input().split()))], 10e9,-1 k = [ math.ceil((ai-i)/n) for i,ai in enumerate(a) ] print(k.index(min(k))+1)

==================

https://mirror.codeforces.com/contest/1082/problem/B

_, string = raw_input(), raw_input()
start, end, res = 0, 0, 0
for char in string:
    if char == "G": start += 1
    else: end, start = start, 0
    res = max(res, start + end + 1)
print min(res, string.count("G"))

==================

https://mirror.codeforces.com/contest/1082/problem/B

x = int(raw_input())
print " ".join(map(str, [x, x])) if x != 1 else -1

==================

https://mirror.codeforces.com/contest/1082/problem/B

n, k = map(int, raw_input().split())
numbers = map(int, raw_input().split())
res, numbers = [], [0] + sorted(list(set(numbers)))
for i in xrange(min(len(numbers) - 1, k)): print (numbers[i + 1] - numbers[i])
for _ in xrange(k - len(numbers) + 1): print 0

==================

https://mirror.codeforces.com/contest/1092/problem/A

for _ in iters():
    n, k = stdin()
    print joint('', ([chr(ord('a') + i%k) for i in xrange(n)]))

==================

*find more here https://github.com/SolbiatiAlessandro/pyComPro

Full text and comments »

By alessandrosolbiati, history, 7 years ago, In English

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; }

Full text and comments »