comingsoon.cpp's blog

By comingsoon.cpp, history, 2 months ago, In English

Hello Guys.. I was trying to solve This atcoder problem From the last beginner contest but i was not able to come up with a working solution during the contest...After some upsolving, i finally came up with a solution that seems to work but the only problem is that it get's TLE on all the tests except the first three for which it passes and I don't know/understand why. This was the first ever ABC problem D that i have attempted after reading the problem statement.

This is the code below and I just need a little help or maybe come hints as to how to make it work because i can't think of a way to optimize it further.

#include <set>
#include <numeric>
#include <algorithm>
#include <vector>
#include <iostream>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;

int check(vector<int> a){
	int q = a.size();
	set<int> s; for(int i = 0; i < q; i++){
		s.insert(a[i]);
	}
	return s.size();
}
void solve(){
	int n , t; cin >> n >> t;
	vector<int> mex; for(int i = 0; i < n; i++) mex.push_back(0);
	for(int i = 0; i < t; i++){
		int a, b; cin >> a >> b;
		mex[a-1] += b;
		cout << check(mex) << endl;
	}
}
int main (){
	ios::sync_with_stdio(false); 
	cin.tie(nullptr);
	//ll t; cin >> t;
	//for(;t--;){
		solve();
	//}
return 0;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By comingsoon.cpp, history, 2 months ago, In English

I was trying to solve an exercise while studying basic probabilities and while solving the exercise, I thought of this problem which I thought was fun, so I decided to share it with my fellow noobs :)

Please if you're anything above a newbie, (in Ercole Visconti's voice) This problem is not for you (no offence) :)

Problem Statement

You have n tiles numbered from 1 through to n. You are also given an integer K. The task it to count all pairs of integers (a,b) from the n tiles whose difference is K. that means (a — b) = K

Input The one and only line of the input contains two positive integer n and K. Output Print the number of such pairs (a, b) whose difference is K, thank you.

Sample input 100 11 Sample output 89

Full text and comments »

  • Vote: I like it
  • +24
  • Vote: I do not like it

By comingsoon.cpp, history, 3 months ago, In English

Hello please i was wondering why my code for This problem B from the last atcoder beginner contest is getting WA for some few tests? This is the code below. I'd really appreciate any help :)

#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;

vector<int> tob(int n){
	vector<int> a;
	for(int i=0; i<n; i++){
		int ans = n%2;
		if(ans==0){
			a.push_back(ans);
		} else{
			break;
		}
		n/=2;
	}
	return a;
}
void solve(){
	//cout << "stuff works" << endl;
	int count = 0;
	int n; cin >> n;
	vector<int> a = tob(n);
	for(auto c : a ) count +=1;
	cout << count << endl;
}
int main (){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//ll T = 1;
	//ll T; cin >> T;
	//for(;T--;){
	solve();
	//}
return 0;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it