++cnt
  • 板块灌水区
  • 楼主Oracynx
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/1/6 21:44
  • 上次更新2024/1/7 08:56:56
查看原帖
++cnt
754324
Oracynx楼主2024/1/6 21:44

今天晚上at,同学C题++cntWA了,但只有C++20会WA,C++17AC,是有什么新语法吗?

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e7 + 10;

int cnt = 1;
pair<int, int>a[N];
signed main() {
	int n, m;
	cin >> n >> m;
	a[1].first = 1, a[1].second = 0;
	while(m--) {
		int op;
		cin >> op;
		if(op == 1) {
			char dir;
			cin >> dir;
			if(dir == 'U') a[++cnt].first = a[cnt - 1].first, a[cnt].second = a[cnt - 1].second + 1;
			if(dir == 'D') a[++cnt].first = a[cnt - 1].first, a[cnt].second = a[cnt - 1].second - 1;
			if(dir == 'L') a[++cnt].first = a[cnt - 1].first - 1, a[cnt].second = a[cnt - 1].second;
			if(dir == 'R') a[++cnt].first = a[cnt - 1].first + 1, a[cnt].second = a[cnt - 1].second;
		}
		else {
			int p;
			cin >> p;
			if(p - 1 > (cnt - 1)) {
				cout << p - cnt + 1 << " " << 0 << endl;
			}
			else {
				int now = cnt - (p - 1);
				//cout << now << endl;
				cout << a[now].first << " " << a[now].second << endl;
			}
		}
	}
} 
2024/1/6 21:44
加载中...