Submission #642565

# Submission time Handle Problem Language Result Execution time Memory
642565 2022-09-20T03:18:10 Z ymm Swapping Cities (APIO20_swap) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 200010;
const int M = 1000010;

vector<int> a[N];
int n, m, d;

bool bin(int x)
{
	queue<int> q;
	Loop (i,0,N) {
		Loop (_,0,a[i].size())
			q.push(i+d);
		if (q.size() && q.front() <= i)
			return 0;
		for (int _=0; _<x && q.size(); ++_)
			q.pop();
	}
	return 1;
}

vector<vector<int>> plan(int x)
{
	vector<vector<int>> ans;
	queue<int> q;
	Loop (i,0,N) {
		for (int j : a[i])
			q.push(j);
		ans.emplace_back();
		for (int _=0; _<x && q.size(); ++_) {
			ans.back().push_back(q.front());
			q.pop();
		}
	}
	return ans;
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> d >> m; ++d;
	Loop (i,0,m) {
		int x;
		cin >> x;
		a[x-1].push_back(i+1);
	}
	int l = 1, r = m;
	while (l < r) {
		int mid = (l+r)/2;
		if (bin(mid))
			r = mid;
		else
			l = mid+1;
	}
	cout << l << '\n';
	auto ans = plan(l);
	Loop (i,0,n) {
		for (int j : ans[i])
			cout << j << ' ';
		cout << "0\n";
	}
}

Compilation message

swap.cpp: In function 'bool bin(int)':
swap.cpp:2:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
swap.cpp:19:3: note: in expansion of macro 'Loop'
   19 |   Loop (_,0,a[i].size())
      |   ^~~~
/usr/bin/ld: /tmp/ccMQwN3E.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccDVdJgE.o:swap.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccMQwN3E.o: in function `main':
grader.cpp:(.text.startup+0x1c3): undefined reference to `init(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
/usr/bin/ld: grader.cpp:(.text.startup+0x217): undefined reference to `getMinimumFuelCapacity(int, int)'
collect2: error: ld returned 1 exit status